Skip to content

Instantly share code, notes, and snippets.

@graingert
Created October 1, 2024 11:32
Show Gist options
  • Save graingert/71ff2fb371a5538df740bc76eedcbdee to your computer and use it in GitHub Desktop.
Save graingert/71ff2fb371a5538df740bc76eedcbdee to your computer and use it in GitHub Desktop.
[run]
branch = True
parallel = True
concurrency = multiprocessing,thread
source_pkgs = demo
graingert@conscientious  venv  ~/projects/coverage_multiprocess_chdir  coverage run demo.py
graingert@conscientious  venv  ~/projects/coverage_multiprocess_chdir  coverage combine
Combined data file .coverage.conscientious.481389.XMZfknLx
Combined data file .coverage.conscientious.481390.XhvFJIXx
graingert@conscientious  venv  ~/projects/coverage_multiprocess_chdir  coverage report -m
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------
demo.py 19 1 6 1 92% 10, 23->exit
-----------------------------------------------------
TOTAL 19 1 6 1 92%
import sys
import multiprocessing
import tempfile
import contextlib
def hit():
pass
def missed():
pass
def go(target):
p = multiprocessing.Process(target=target)
p.start()
p.join()
def main():
go(hit)
with tempfile.TemporaryDirectory() as tmp:
with contextlib.chdir(tmp):
go(missed)
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment