-
Notifications
You must be signed in to change notification settings - Fork 216
Prevent unimported warnings @ pytest-xdist workers #695
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
base: master
Are you sure you want to change the base?
Prevent unimported warnings @ pytest-xdist workers #695
Conversation
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.
Pull Request Overview
This PR suppresses spurious “unimported source” warnings when collecting coverage under pytest-xdist workers.
- Disables the private
_warn_unimported_source
flag on the coverage object inDistMaster.start()
. - Ensures coverage collection proceeds without warnings in parallel test sessions.
Comments suppressed due to low confidence (1)
src/pytest_cov/engine.py:453
- Add a test to verify that 'unimported source' warnings are suppressed under xdist worker mode to guard against regressions.
self.cov._warn_unimported_source = False
@@ -450,6 +450,7 @@ def start(self): | |||
data_suffix=_data_suffix(f'w{self.nodeid}'), | |||
config_file=self.cov_config, | |||
) | |||
self.cov._warn_unimported_source = 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.
This should probably include all those other hacks, after all:
self.cov._warn_unimported_source = False | |
self.cov._warn_no_data = False | |
self.cov._warn_unimported_source = False | |
self.cov._warn_preimported_source = 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.
Perhaps, but without a test triggering these warnings you will never really know what effect this will have.
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.
Yeah, I only know that only one has a visible effect of suppressing a false negative in ansible-pylibssh. I've been trying to think of a reliable test but no luck so far.
Ref #693
This fixes #693 (comment) for me.
Actually, locally, I can also drop these private attribute assignments from
DistMaster
and it works with just disabling a single warning on the worker.However, when I tried doing this in the project (and not in site-packages of where I'm hitting the problem), it breaks
tests/test_pytest_cov.py::test_xdist_no_data_collected
so I didn't include those changes.I was hoping that you @ionelmc could take a look and maybe come up with some explanation of why this is happening.
Coverage is being collected and reported, but at the time
coveragepy
is looking intosys.modules
, the module isn't there. I think xdist makes it unpredictable whether the coverage object in master or in the worker would hit this code path. It probably makes sense to disable this warning when under xdist for workers too. It's unreliable at best in such a setup.