From 604047ee1a09d4286372f144addb60a1504aef18 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 16 Sep 2020 11:13:17 +0100 Subject: [PATCH] Improve output for missing required plugins/unknown config keys (#7723) Co-authored-by: Florian Bruhin --- changelog/7572.improvement.rst | 1 + src/_pytest/config/__init__.py | 3 +-- testing/test_config.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 changelog/7572.improvement.rst diff --git a/changelog/7572.improvement.rst b/changelog/7572.improvement.rst new file mode 100644 index 000000000..b42da81c1 --- /dev/null +++ b/changelog/7572.improvement.rst @@ -0,0 +1 @@ +When a plugin listed in ``required_plugins`` is missing, a simple error message is now shown instead of a stacktrace. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index f4e0d5d0f..ae0f15bfc 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1174,9 +1174,8 @@ class Config: missing_plugins.append(required_plugin) if missing_plugins: - fail( + raise UsageError( "Missing required plugins: {}".format(", ".join(missing_plugins)), - pytrace=False, ) def _warn_or_fail_if_strict(self, message: str) -> None: diff --git a/testing/test_config.py b/testing/test_config.py index 9b1c11d5e..e2881c27d 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -362,7 +362,7 @@ class TestParseIni: testdir.makeini(ini_file_text) if exception_text: - with pytest.raises(pytest.fail.Exception, match=exception_text): + with pytest.raises(pytest.UsageError, match=exception_text): testdir.parseconfig() else: testdir.parseconfig()