Skip to content

Handled CollectReport without duration attribute in terminal report #13573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 change: 1 addition & 0 deletions changelog/13478.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a crash when using :confval:`console_output_style` with ``times`` and a module is skipped.
4 changes: 3 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ def _get_progress_information_message(self) -> str:
last_in_module = tests_completed == tests_in_module
if self.showlongtestinfo or last_in_module:
self._timing_nodeids_reported.update(r.nodeid for r in not_reported)
return format_node_duration(sum(r.duration for r in not_reported))
return format_node_duration(
sum(r.duration for r in not_reported if isinstance(r, TestReport))
)
return ""
if collected:
return f" [{len(self._progress_nodeids_reported) * 100 // collected:3d}%]"
Expand Down
25 changes: 25 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ def test_func():
[" def test_func():", "> assert 0", "E assert 0"]
)

def test_console_output_style_times_with_skipped_and_passed(
self, pytester: Pytester
) -> None:
pytester.makepyfile(
test_repro="""
def test_hello():
pass
""",
test_repro_skip="""
import pytest
pytest.importorskip("fakepackage_does_not_exist")
""",
)
result = pytester.runpytest(
"test_repro.py",
"test_repro_skip.py",
"-o",
"console_output_style=times",
)

result.stdout.fnmatch_lines("* 1 passed, 1 skipped in *")

combined = "\n".join(result.stdout.lines + result.stderr.lines)
assert "INTERNALERROR" not in combined

def test_internalerror(self, pytester: Pytester, linecomp) -> None:
modcol = pytester.getmodulecol("def test_one(): pass")
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
Expand Down