Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/transformers/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,10 @@ def wrapper(*args, **kwargs):

env = copy.deepcopy(os.environ)
env["_INSIDE_SUB_PROCESS"] = "1"
# This prevents the entries in `short test summary info` given by the subprocess being truncated. so the
# full information can be passed to the parent pytest process.
# See: https://docs.pytest.org/en/stable/explanation/ci.html
env["CI"] = "true"

# If not subclass of `unitTest.TestCase` and `pytestconfig` is used: try to grab and use the arguments
if "pytestconfig" in kwargs:
Expand All @@ -2402,6 +2406,22 @@ def wrapper(*args, **kwargs):
subprocess.run(command, env=env, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
exception_message = e.stdout.decode()
lines = exception_message.split("\n")
# Add a first line with more informative information instead of just `= test session starts =`.
# This makes the `short test summary info` section more useful.
if "= test session starts =" in lines[0]:
text = ""
for line in lines[1:]:
if line.startswith("FAILED "):
text = line[len("FAILED ") :]
text = "".join(text.split(" - ")[1:])
elif line.startswith("=") and line.endswith("=") and " failed in " in line:
break
elif len(text) > 0:
text += f"\n{line}"
text = "(subprocess) " + text
lines = [text] + lines
exception_message = "\n".join(lines)
Comment on lines +2409 to +2424
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, what is shown in the (final) short test summary info is something like

/transformers/src/transformers/testing_utils.py:2420: ==== test session starts ====

which is not very informative.

And for the same test, we get two FAILED in the log: one from the subprocess and another one is the original pytest process. This causes slack CI report script fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah got it thanks for explaining

raise pytest.fail(exception_message, pytrace=False)

return wrapper
Expand Down
10 changes: 10 additions & 0 deletions utils/notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ def prepare_reports(title, header, reports, to_truncate=True):

for line in artifact["summary_short"].split("\n"):
if line.startswith("FAILED "):
# Avoid the extra `FAILED` entry given by `run_test_using_subprocess` causing issue when calling
# `stacktraces.pop` below.
# See `run_test_using_subprocess` in `src/transformers/testing_utils.py`
if " - Failed: (subprocess)" in line:
continue
line = line[len("FAILED ") :]
line = line.split()[0].replace("\n", "")

Expand Down Expand Up @@ -1186,6 +1191,11 @@ def prepare_reports(title, header, reports, to_truncate=True):
if failed:
for line in artifact["summary_short"].split("\n"):
if line.startswith("FAILED "):
# Avoid the extra `FAILED` entry given by `run_test_using_subprocess` causing issue when calling
# `stacktraces.pop` below.
# See `run_test_using_subprocess` in `src/transformers/testing_utils.py`
if " - Failed: (subprocess)" in line:
continue
line = line[len("FAILED ") :]
line = line.split()[0].replace("\n", "")

Expand Down