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
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
34 changes: 34 additions & 0 deletions testing/test_terminal_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

from _pytest.pytester import Pytester


def test_console_output_style_times_with_skipped_and_passed(pytester: Pytester) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why this test is not added to test_terminal.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @nicoddemus , test_terminal.py was already existing,, so thought of making another new unit test file. Shall I add this in that existing file only? please let me know

Copy link
Member

Choose a reason for hiding this comment

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

Yes please. 👍

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",
)

print("Captured stdout:")
print(result.stdout.str())
print("Captured stderr:")
print(result.stderr.str())

combined = result.stdout.lines + result.stderr.lines
assert any(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I follow, doesn't the change in terminal.py prevents this message from appearing in the command line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this fix mainly prevents the AttributeError from showing up, which is expected now asthe bug is resolved.

Copy link
Member

Choose a reason for hiding this comment

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

But the fact that the bug is fixed, means that the message does not show up, correct? any is testing that it should show up, which is wrong.

"'CollectReport' object has no attribute 'duration'" in line
for line in combined
)
Loading