-
Notifications
You must be signed in to change notification settings - Fork 595
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
Fix statistics reporting when running under pytest-xdist #1577
Conversation
0f072ab
to
2ca37a5
Compare
@@ -120,42 +124,36 @@ def pytest_runtest_makereport(item, call): | |||
'Hypothesis', | |||
'\n'.join(item.hypothesis_report_information) | |||
)) | |||
if hasattr(item, 'hypothesis_statistics') and report.when == 'teardown': | |||
# Running on pytest <= 3.5 where user_properties doesn't exist, fall |
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.
This says <= 3.5
but the code before checks for < 3.5
. Which is it?
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 code is correct, and the comment now fixed.
terminalreporter.write_line(' - Test was never run') | ||
continue | ||
if LooseVersion(pytest.__version__) < '3.5': # pragma: no cover | ||
if terminalreporter.config.getoption('-n'): |
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.
This feels like a very fragile way to check if a plugin is enabled. Is there really not a better one?
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.
Nope 😭
We can robustly check if the xdist
plugin is installed, and we can robustly check if the current process one of the workers (and if so which one), but there's no way I can find to distinguish between being the master process and xdist
not being enabled.
(I did add a check for the --numprocesses
form, even though I've never seen it in the wild)
' * %s' % (event,) | ||
) | ||
terminalreporter.write_line('') | ||
for test_report in terminalreporter.stats['']: |
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.
What is .stats['']
in this context?
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.
Magic. It's the only place the list of TestReport
objects seems to be stored; I copied this from an example plugin and it works even though I can't find where the entry is added to the dict.
I've added a comment which will would help me debug it when if this breaks later. Fortunately we have tests that will fail immediately if it does!
e46455a
to
d080b59
Compare
d080b59
to
23f24dd
Compare
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 confess I don't entirely understand the pytest interaction, but I think that's more because pytest than anything you can fix! At any rate, the testing looks good, and it's at least better than the status quo, so LGTM.
Mmm, suffice to say that Pytest has taken a variety of approaches that I would not choose over the years, and that the |
Closes #700.
I moved some reporting code to
Statistics.get_description()
, becausexdist
can move lists of strings between processes but not arbitrary objects. Hopefully this will be useful for future work on #437.