-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
terminal: fix progress report with duplicate nodeids #6599
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
Conversation
859b0bb
to
f70ae66
Compare
b059834
to
cc26d81
Compare
cc26d81
to
aac97ef
Compare
What's needed to fix pytest-dev#3088 seems to be checking for `rep.when == "setup"`. This then needs adjustments though (to code done in pytest-dev#3110) to make this work with xdist. It appears to make sense to split it into hooks that are run per test (for eventually writing if past edge), and one that gets run at the end really (not requiring to check for "last item" then).
TODO: - `test_xdist_verbose` fails: first two tests are reporting at 10% already. Conflicts: changelog/6597.bugfix.rst src/_pytest/terminal.py testing/test_terminal.py
be6a7cd changes a lot, but is actually a bit of a revert, see the commit message. |
According to this comment by @nicoddemus, duplicate nodeids are no longer possible. The change (set -> counter) might still make sense, but maybe the test doesn't? |
@bluetech nothing prevents you from creating duplicate nodeids. The test here uses a private property, but you could also yield The test is for a corner case, yes, but makes sense. It's also unfortunate that the patch is so big, but only because it was not done properly/better before and it has to undo previous changes (IIRC). |
Some lazy questions that would help me understand the diff -- feel free to dismiss. Considering each change I can detect separately:
|
@@ -440,6 +440,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: | |||
else: | |||
markup = None | |||
self._add_stats(category, [rep]) | |||
if rep.when == "call" or (rep.when == "setup" and rep.failed): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this come after if not letter and not word:
? Because "probably passed setup/teardown" should not be reported again.
src/_pytest/terminal.py
Outdated
progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests))) | ||
else: | ||
progress_length = len(" [100%]") | ||
def pytest_runtest_teardown(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, why using pytest_runtest_teardown
instead of pytest_runtest_logfinish
? On pytest-xdist I think pytest_runtest_teardown
is called only on worker nodes (because they actually run the tests), not on master
(which only does reporting). The pytest_runtest_log*
run on both master
and workers
, by design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm strange, I commented out this function from your branch, and I still get the exact same output both with xdist/without, and -v
and normal modes.
With the patch as is:
λ pytest testing\test_nodes.py
======================== test session starts ========================
collected 11 items
testing\test_nodes.py ........... [100%]
======================== 11 passed in 0.10s =========================
Commenting out pytest_runtest_teardown
:
λ pytest testing\test_nodes.py
======================== test session starts ========================
collected 11 items
testing\test_nodes.py ........... [100%]
======================== 11 passed in 0.10s =========================
With the patch as is:
λ pytest testing\test_nodes.py -n2
======================== test session starts ========================
gw0 [11] / gw1 [11]
........... [100%]
======================== 11 passed in 0.93s =========================
Commenting out pytest_runtest_teardown
:
λ pytest testing\test_nodes.py -n2
======================== test session starts ========================
gw0 [11] / gw1 [11]
........... [100%]
======================== 11 passed in 0.92s =========================
So I guess pytest_runtest_teardown
is not being used?
I got curious, and when in master
and pytest_runtest_logfinish
commented out, the [%]
progress indicator is not printed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pytest_runtest_log* run on both master and workers, by design.
That might result in too much being reported then (if both master and nodes report the same item(s)).
Changed it to use pytest_runtest_logfinish again, let's see if it passes.
"""Write final progress indicator.""" | ||
yield | ||
if ( | ||
getattr(self, "_tests_ran", False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid attributes being set but not declared on __init__
when that is possible; this has been a great source of confusion/bugs in the past.
IIRC the former, because it is easier/more solid to just use the node ids if they are unique. But indeed, there's nothing preventing plugins to create items with duplicated ids, so using a |
@nicoddemus @bluetech |
(btw: nodeids were generated automatically not too long ago, which is actually something I've came up with somewhere already: 5e59357) |
Fixes #6597.
TODO: