question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pytest-cov leaves .coverage.hostname.number.number data files if running tests against multiprocessing.Pool

See original GitHub issue

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:

pipenv shell; pipenv install

Pipfile

pytest = "*"
pytest-cov = "*"
pytest-mock = "*"
tox-pipenv = "*"
pytest-pythonpath = "*"

Detailed steps to reproduce the bug:

pytest --cov=src --cov-report=term-missing  tests/test_cov_pool.py

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

8reactions
ionelmccommented, Feb 16, 2019

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 Pool.__exit__ sends KILL in addition to TERM …

0reactions
ionelmccommented, May 21, 2020

@GergelyKalmar please open a new issue and add details

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subprocess support — pytest-cov 4.0.0 documentation
Normally coverage writes the data via a pretty standard atexit handler. However, if the ... The finalizer will only run reliably if the...
Read more >
Coverage.py - Read the Docs
Coverage.py has a number of commands: • run – Run a Python program and collect execution data. • combine – Combine together a...
Read more >
latest PDF - pytest Documentation
pytest minimizes the number of active fixtures during test runs. If you have a parametrized fixture, then all the tests using.
Read more >
PDF Mastering Python - Index of /
Package data. 438. Testing packages. 439. Unittest. 439 py.test ... Now that you are the proud owner of a Packt book, we have...
Read more >
Bug listing with status UNCONFIRMED as at 2022/12/22 02 ...
Bug:128538 - "sys-apps/coreutils: /bin/hostname should be installed from ... "app-benchmarks/mmtests - a configurable test suite that runs a number of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found