Skip to content

Commit

Permalink
fix: suffix=False will suppress the suffix even with multiprocessing. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 18, 2021
1 parent 181d71c commit 2094909
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ 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.

- Debug: The `coverage debug` command used to accept a number of topics at a
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


Expand Down
7 changes: 6 additions & 1 deletion coverage/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 2094909

Please sign in to comment.