Skip to content

Commit b9d304d

Browse files
VXNCXNXnedbat
andauthored
fix: check for multiprocessing in a --concurrency list (#2270)
* fix: check for multiprocessing in a --concurrency list * chore: link the changelog entry to the PR --------- Co-authored-by: VXNCXNX <[email protected]> Co-authored-by: Ned Batchelder <[email protected]>
1 parent a6ef928 commit b9d304d

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎CHANGES.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ Unreleased
5151
entry), file settings like ``data_file``, and any wrong-typed value in the
5252
``[paths]`` section (`pull 2263`_).
5353

54+
- Fix: ``coverage run`` refuses run-affecting command-line options like
55+
``--branch`` alongside ``--concurrency=multiprocessing``, since they can't
56+
reach the subprocesses. The check only recognized ``multiprocessing`` as the
57+
entire option value, so ``--concurrency=multiprocessing,thread --branch``
58+
slipped through and failed later with "Can't combine statement coverage data
59+
with branch data". Each named concurrency library is now considered (`pull
60+
2270`_).
61+
5462
- Fix: ``coverage annotate -d DIR`` raised an ``AssertionError`` if any
5563
measured file had an extension other than ``.py``, such as a ``.pyw`` file on
5664
Windows. The original extension is now restored on the annotated copy (`pull
@@ -60,6 +68,7 @@ Unreleased
6068
.. _pull 2262: https://github.com/coveragepy/coveragepy/pull/2262
6169
.. _pull 2263: https://github.com/coveragepy/coveragepy/pull/2263
6270
.. _pull 2265: https://github.com/coveragepy/coveragepy/pull/2265
71+
.. _pull 2270: https://github.com/coveragepy/coveragepy/pull/2270
6372
.. _issue 2266: https://github.com/coveragepy/coveragepy/issues/2266
6473
.. _pull 2268: https://github.com/coveragepy/coveragepy/pull/2268
6574

‎coverage/cmdline.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ def do_run(self, options: optparse.Values, args: list[str]) -> int:
10171017
show_help("Can't append to data files in parallel mode.")
10181018
return ERR
10191019

1020-
if options.concurrency == "multiprocessing":
1020+
if "multiprocessing" in (options.concurrency or "").split(","):
10211021
# Can't set other run-affecting command line options with
10221022
# multiprocessing.
10231023
for opt_name in ["branch", "include", "omit", "pylib", "source", "timid"]:

‎tests/test_cmdline.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,18 @@ def test_multiprocessing_needs_config_file(self) -> None:
11811181
assert msg in err
11821182
assert "Remove --branch from the command line." in err
11831183

1184+
def test_multiprocessing_in_a_list_needs_config_file(self) -> None:
1185+
# The check has to consider each concurrency value, not just compare
1186+
# the whole option to "multiprocessing".
1187+
self.cmd_help(
1188+
"run --concurrency=multiprocessing,thread --branch foo.py",
1189+
help_msg=(
1190+
"Options affecting multiprocessing must only be specified "
1191+
+ "in a configuration file.\n"
1192+
+ "Remove --branch from the command line."
1193+
),
1194+
)
1195+
11841196
def test_run_debug(self) -> None:
11851197
self.cmd_executes(
11861198
"run --debug=opt1 foo.py",

0 commit comments

Comments
 (0)