-
Notifications
You must be signed in to change notification settings - Fork 212
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
Pytest-cov leaves .coverage.hostname.number.number data files if running tests against multiprocessing.Pool #250
Comments
@ionelmc Hi, any thoughts on this? |
Try running |
It gets created during
If I execute |
That looks like it is using the new format from coveragepy 5. You can try exporting COVERAGE_DEBUG (see the coveragepy docs to get more information). |
It happens with both coverage 5 and 4.5.2 |
Looking at "config_reads:" indicates that it always uses your tox.ini, that looks fine. What I've meant is that the error looks like coverage 4 might read a file created by 5. |
@blueyed I use pipenv and clean envs, so there's no way that coverage 4 and 5 files can be mixed. |
Updated the gist above with the debug output containing |
So then you were using coverage 5 with the following error:
Have you inspected the file? Is it maybe just empty? Maybe coveragepy is crashing after all. Anyway, I cannot really help further I guess. |
Yep it's empty and I think it's the same problem as in #100 for no particular reason. I tested it both with coverage 4 and 5 and in both versions the problem persists. |
You could try to figure out where it gets created from: either from/based on logs (search for the pid from the filename there), and/or by bisecting your tests (i.e. run the first 50% first, etc), and figure out from there which test creates it. |
So I've traced a bit the example. It turns out that once in a while there's an unclean shutdown, eg:
|
So this really simple trick (/s) makes the problem go away: @@ -14,7 +14,8 @@ def get_items_with_pool(count: int, start_index: int = 0):
processes_count = os.cpu_count()
batch_size = math.ceil(count / processes_count)
- with Pool(processes_count) as p:
+ p = Pool(processes_count)
+ try:
results = p.starmap(
get_items,
zip(
@@ -24,10 +25,7 @@ def get_items_with_pool(count: int, start_index: int = 0):
)
for items_batch in results:
items.extend(items_batch)
- p.join()
+ finally:
+ p.close()
+ p.join()
return items For some reason |
So my plan for handling this situation is to offer users two solutions:
|
So the secondary issue if you use Thus sometimes while the finalizer runs the signal handler will also run and leave one unfinished file around (it will |
I am randomly seeing something very similar to this on CI, where we wipe everyting between runs. See https://dashboard.zuul.ansible.com/t/ansible/build/28f84185f22a448f92f00f47253fc931 My impression is that happens only on py27 jobs but still is a PITA and I do not know what to do to avoid it. |
I also see this issue on TravisCI, running Windows server, python 3.6 and python 3.7. Scroll down to the bottom of the output here: https://travis-ci.com/cgnorthcutt/cleanlab/jobs/291188046 |
This forced me to pin down coverage version below 4 for all versions of python. Mainly this is caused by the fact the coverage expects all files to be generated using the same version of coverage. If you happen to still support py27, you are forced to use older coverage for all environments, not only those using py27. I guess that the decision to drop py27 support backfires because it forces many users to avoid newer version completely. |
It seems that I keep seeing these random-like errors https://dashboard.zuul.ansible.com/t/ansible/build/fa4b20a11a484ee39050b11f619484b1 -- still more likely on py27. |
Hi, Thanks! |
This issue seems to have appeared for me too with coverage 5.0 and pytest 5.4.2. |
@GergelyKalmar please open a new issue and add details |
Running pytest with coverage for tests against multiprocessing.Pool generates several data files, but not all of them are cleaned after. It looks similar to #100.
Pool.join()
doesn't seem to change anything.Example filename
.coverage.myhost.local.7582.948066
Here's the repository to reproduce: https://github.com/manycoding/pytest_cov_pool_datafiles_250
Your operating system name and version:
Mac OS Mojave 10.14 (18A391)
Any details about your local setup that might be helpful in troubleshooting:
Pipfile
Detailed steps to reproduce the bug:
The text was updated successfully, but these errors were encountered: