Fix statistics reporting when running under pytest-xdist#1577
Conversation
0f072ab to
2ca37a5
Compare
| '\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.
This says <= 3.5 but the code before checks for < 3.5. Which is it?
There was a problem hiding this comment.
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.
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.
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.
What is .stats[''] in this context?
There was a problem hiding this comment.
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
DRMacIver
left a comment
There was a problem hiding this comment.
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(), becausexdistcan move lists of strings between processes but not arbitrary objects. Hopefully this will be useful for future work on #437.