diff --git a/.coveragerc b/.coveragerc index b4e940b7..703ae66d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,3 @@ -# Coverage isn't really compatible with subprocesses so results are unreliable - [paths] source = src @@ -8,9 +6,11 @@ source = [run] branch = true parallel = true +concurrency = + thread + multiprocessing source = src/ocrmypdf - tests omit = tests/spoof/* diff --git a/tests/conftest.py b/tests/conftest.py index 075e004e..90e9057d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -229,13 +229,21 @@ def run_ocrmypdf(input_file, output_file, *args, env=None, universal_newlines=Tr "Run ocrmypdf and let caller deal with results" if env is None: - env = os.environ + env = os.environ.copy() p_args = ( OCRMYPDF + [str(arg) for arg in args if arg is not None] + [str(input_file), str(output_file)] ) + + # Tell subprocess where to find coverage.py configuration + # This has no effect except when coverage is running + # Details: https://coverage.readthedocs.io/en/coverage-5.0/subprocess.html + coverage_rc = Path(__file__).parent.parent / '.coveragerc' + assert coverage_rc.exists() + env['COVERAGE_PROCESS_START'] = os.fspath(coverage_rc) + p = run( p_args, stdout=PIPE, stderr=PIPE, universal_newlines=universal_newlines, env=env )