From 2094909df35db45ca7a409cc37f38d49c3191d2a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 18 Nov 2021 06:16:55 -0500 Subject: [PATCH] fix: suffix=False will suppress the suffix even with multiprocessing. #989 --- CHANGES.rst | 5 +++++ coverage/control.py | 7 ++++++- tests/test_api.py | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1d9ec9225..0c48b706a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -37,6 +37,10 @@ Unreleased - API: The exceptions raised by Coverage.py have been specialized, to provide finer-grained catching of exceptions by third-party code. +- API: Using ``suffix=False`` when constructing a Coverage object with + multiprocessing wouldn't suppress the data file suffix (`issue 989`_). This + is now fixed. + - Debug: The `coverage debug data` command will now sniff out combinable data files, and report on all of them. @@ -44,6 +48,7 @@ Unreleased time, and show all of them, though this was never documented. This no longer works, to allow for command-line options in the future. +.. _issue 989: https://github.com/nedbat/coveragepy/issues/989 .. _issue 1203: https://github.com/nedbat/coveragepy/issues/1203 diff --git a/coverage/control.py b/coverage/control.py index ce8ce153f..00836b3cc 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -482,10 +482,15 @@ def _init_for_start(self): ) suffix = self._data_suffix_specified - if suffix or self.config.parallel: + if suffix: if not isinstance(suffix, str): # if data_suffix=True, use .machinename.pid.random suffix = True + elif self.config.parallel: + if suffix is None: + suffix = True + elif not isinstance(suffix, str): + suffix = bool(suffix) else: suffix = None diff --git a/tests/test_api.py b/tests/test_api.py index 6b0657096..a76fe3b9c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1199,3 +1199,23 @@ def test_combine_relative(self): assert files == {'foo.py', 'bar.py', os_sep('modsrc/__init__.py')} res = cov.report() assert res == 100 + + def test_combine_no_suffix_multiprocessing(self): + self.make_file(".coveragerc", """\ + [run] + branch = True + """) + cov = coverage.Coverage( + config_file=".coveragerc", + concurrency="multiprocessing", + data_suffix=False, + ) + cov.start() + cov.stop() + # The warning isn't the point of this test, but suppress it. + with pytest.warns(Warning) as warns: + cov.combine() + assert_coverage_warnings(warns, "No data was collected. (no-data-collected)") + cov.save() + self.assert_file_count(".coverage.*", 0) + self.assert_exists(".coverage")