From 32ff8715f080c5a3cfbeb605daa929f424b1e748 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 9 Feb 2022 06:06:32 -0500 Subject: [PATCH] fix: provide an intelligible error message for multiprocessing with no config file. #1320 --- CHANGES.rst | 5 +++++ coverage/control.py | 2 ++ tests/test_concurrency.py | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 2111d8759..f6371b23d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,11 @@ Unreleased - Debug: added ``pybehave`` to the list of :ref:`cmd_debug` and :ref:`cmd_run_debug` options. +- Fix: show an intelligible error message if ``--concurrency=multiprocessing`` + is used without a configuration file. Closes `issue 1320`_. + +.. _issue 1320: https://github.com/nedbat/coveragepy/issues/1320 + .. _changes_631: diff --git a/coverage/control.py b/coverage/control.py index 0f9f675e2..910cfb083 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -462,6 +462,8 @@ def _init_for_start(self): raise ConfigError( # pragma: only jython "multiprocessing is not supported on this Python" ) + if self.config.config_file is None: + raise ConfigError("multiprocessing requires a configuration file") patch_multiprocessing(rcfile=self.config.config_file) dycon = self.config.dynamic_context diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 5665e37f5..1217142a7 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -369,6 +369,10 @@ def test_no_multiple_light_concurrency_in_config(self): with pytest.raises(ConfigError, match="Conflicting concurrency settings: eventlet, gevent"): self.command_line("run prog.py") + def test_multiprocessing_needs_config_file(self): + with pytest.raises(ConfigError, match="multiprocessing requires a configuration file"): + self.command_line("run --concurrency=multiprocessing prog.py") + class WithoutConcurrencyModuleTest(CoverageTest): """Tests of what happens if the requested concurrency isn't installed."""