From fc93d33b786f73282671f6223485a772bf851684 Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 14 Jul 2021 07:57:36 +0000 Subject: [PATCH 1/3] Update error message for module level skip with 'allow_module_level' --- changelog/8432.doc.rst | 1 + src/_pytest/python.py | 8 ++++---- testing/test_skipping.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 changelog/8432.doc.rst diff --git a/changelog/8432.doc.rst b/changelog/8432.doc.rst new file mode 100644 index 00000000000..48fb7c389c3 --- /dev/null +++ b/changelog/8432.doc.rst @@ -0,0 +1 @@ +Update error message for module level skip with `allow_module_level`. diff --git a/src/_pytest/python.py b/src/_pytest/python.py index d6c14ea520a..cdd6b51c270 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -608,10 +608,10 @@ def _importtestmodule(self): if e.allow_module_level: raise raise self.CollectError( - "Using pytest.skip outside of a test is not allowed. " - "To decorate a test function, use the @pytest.mark.skip " - "or @pytest.mark.skipif decorators instead, and to skip a " - "module use `pytestmark = pytest.mark.{skip,skipif}." + "Using pytest.skip outside will skip the entire module, " + "if that's your intention pass `allow_module_level=True`. " + "If you want to skip a specific test or entire class, " + "use the @pytest.mark.skip or @pytest.mark.skipif decorators." ) from e self.config.pluginmanager.consider_module(mod) return mod diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 53bf953a823..9908e5b07ac 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1341,7 +1341,7 @@ def test_func(): ) result = pytester.runpytest() result.stdout.fnmatch_lines( - ["*Using pytest.skip outside of a test is not allowed*"] + ["*Using pytest.skip outside will skip the entire module*"] ) From 8364c0375b58a636a8a21256a7c63556399e43c3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 14 Jul 2021 09:26:40 -0300 Subject: [PATCH 2/3] Tweak changelog message --- changelog/8432.doc.rst | 1 - changelog/8432.trivial.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 changelog/8432.doc.rst create mode 100644 changelog/8432.trivial.rst diff --git a/changelog/8432.doc.rst b/changelog/8432.doc.rst deleted file mode 100644 index 48fb7c389c3..00000000000 --- a/changelog/8432.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Update error message for module level skip with `allow_module_level`. diff --git a/changelog/8432.trivial.rst b/changelog/8432.trivial.rst new file mode 100644 index 00000000000..af4c7a22617 --- /dev/null +++ b/changelog/8432.trivial.rst @@ -0,0 +1 @@ +Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`. From 30354765ed9af7f77e1b70f6b246e999a3f0632e Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 14 Jul 2021 13:08:31 +0000 Subject: [PATCH 3/3] Tweak error message --- src/_pytest/python.py | 6 +++--- testing/test_skipping.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index cdd6b51c270..420a969796a 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -608,9 +608,9 @@ def _importtestmodule(self): if e.allow_module_level: raise raise self.CollectError( - "Using pytest.skip outside will skip the entire module, " - "if that's your intention pass `allow_module_level=True`. " - "If you want to skip a specific test or entire class, " + "Using pytest.skip outside of a test will skip the entire module. " + "If that's your intention, pass `allow_module_level=True`. " + "If you want to skip a specific test or an entire class, " "use the @pytest.mark.skip or @pytest.mark.skipif decorators." ) from e self.config.pluginmanager.consider_module(mod) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 9908e5b07ac..d50a16c9078 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1341,7 +1341,7 @@ def test_func(): ) result = pytester.runpytest() result.stdout.fnmatch_lines( - ["*Using pytest.skip outside will skip the entire module*"] + ["*Using pytest.skip outside of a test will skip the entire module*"] )