From 119d746b764e992399a6047032593d6fbe4cd1b4 Mon Sep 17 00:00:00 2001 From: Harm Geerts Date: Mon, 20 Jan 2020 14:33:27 +0100 Subject: [PATCH 1/2] Always enable data_suffix for --cov-append Setting `data_suffix=True` will also enable `parallel=True` and ensure the coverage processes do not conflict with each other. Because pytest-cov always combines the coverage result this is safe to enable. --- src/pytest_cov/engine.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index 5c05aa55..b23b616f 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -218,6 +218,7 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, + data_suffix=True, config_file=self.cov_config) self.combining_cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, From b9f7ea17fb619a53fbe25f343a77c76fb4ba0a63 Mon Sep 17 00:00:00 2001 From: Harm Geerts Date: Tue, 21 Jan 2020 13:37:49 +0100 Subject: [PATCH 2/2] Test for --cov-append with sub/parallel processes --- tests/test_pytest_cov.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index 02027b62..fae28ad5 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -1869,6 +1869,29 @@ def test_do_not_append_coverage(testdir, opts, prop): ]) +@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"') +def test_append_coverage_subprocess(testdir): + scripts = testdir.makepyfile(parent_script=SCRIPT_PARENT, + child_script=SCRIPT_CHILD) + parent_script = scripts.dirpath().join('parent_script.py') + + result = testdir.runpytest('-v', + '--cov=%s' % scripts.dirpath(), + '--cov-append', + '--cov-report=term-missing', + '--dist=load', + '--tx=2*popen', + max_worker_restart_0, + parent_script) + + result.stdout.fnmatch_lines([ + '*- coverage: platform *, python * -*', + 'child_script* %s*' % CHILD_SCRIPT_RESULT, + 'parent_script* %s*' % PARENT_SCRIPT_RESULT, + ]) + assert result.ret == 0 + + def test_pth_failure(monkeypatch): with open('src/pytest-cov.pth') as fh: payload = fh.read()