Skip to content

Commit 275b7df

Browse files
coder-aditiCoderAAAnicoddemus
authored andcommitted
Fix crash with times output style and skipped module (pytest-dev#13573)
Fixes pytest-dev#13478 --------- Co-authored-by: AD <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 36f2c16 commit 275b7df

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

changelog/13478.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a crash when using :confval:`console_output_style` with ``times`` and a module is skipped.

src/_pytest/terminal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ def _get_progress_information_message(self) -> str:
734734
last_in_module = tests_completed == tests_in_module
735735
if self.showlongtestinfo or last_in_module:
736736
self._timing_nodeids_reported.update(r.nodeid for r in not_reported)
737-
return format_node_duration(sum(r.duration for r in not_reported))
737+
return format_node_duration(
738+
sum(r.duration for r in not_reported if isinstance(r, TestReport))
739+
)
738740
return ""
739741
if collected:
740742
return f" [{len(self._progress_nodeids_reported) * 100 // collected:3d}%]"

testing/test_terminal.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ def test_func():
112112
[" def test_func():", "> assert 0", "E assert 0"]
113113
)
114114

115+
def test_console_output_style_times_with_skipped_and_passed(
116+
self, pytester: Pytester
117+
) -> None:
118+
pytester.makepyfile(
119+
test_repro="""
120+
def test_hello():
121+
pass
122+
""",
123+
test_repro_skip="""
124+
import pytest
125+
pytest.importorskip("fakepackage_does_not_exist")
126+
""",
127+
)
128+
result = pytester.runpytest(
129+
"test_repro.py",
130+
"test_repro_skip.py",
131+
"-o",
132+
"console_output_style=times",
133+
)
134+
135+
result.stdout.fnmatch_lines("* 1 passed, 1 skipped in *")
136+
137+
combined = "\n".join(result.stdout.lines + result.stderr.lines)
138+
assert "INTERNALERROR" not in combined
139+
115140
def test_internalerror(self, pytester: Pytester, linecomp) -> None:
116141
modcol = pytester.getmodulecol("def test_one(): pass")
117142
rep = TerminalReporter(modcol.config, file=linecomp.stringio)

0 commit comments

Comments
 (0)