Skip to content

Commit febb978

Browse files
Naveen-PratapNaveennicoddemus
authored
Update error message for module level skip to include 'allow_module_level' (#8906)
Co-authored-by: Naveen <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 69356d2 commit febb978

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

changelog/8432.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`.

src/_pytest/python.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,10 @@ def _importtestmodule(self):
608608
if e.allow_module_level:
609609
raise
610610
raise self.CollectError(
611-
"Using pytest.skip outside of a test is not allowed. "
612-
"To decorate a test function, use the @pytest.mark.skip "
613-
"or @pytest.mark.skipif decorators instead, and to skip a "
614-
"module use `pytestmark = pytest.mark.{skip,skipif}."
611+
"Using pytest.skip outside of a test will skip the entire module. "
612+
"If that's your intention, pass `allow_module_level=True`. "
613+
"If you want to skip a specific test or an entire class, "
614+
"use the @pytest.mark.skip or @pytest.mark.skipif decorators."
615615
) from e
616616
self.config.pluginmanager.consider_module(mod)
617617
return mod

testing/test_skipping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def test_func():
13411341
)
13421342
result = pytester.runpytest()
13431343
result.stdout.fnmatch_lines(
1344-
["*Using pytest.skip outside of a test is not allowed*"]
1344+
["*Using pytest.skip outside of a test will skip the entire module*"]
13451345
)
13461346

13471347

0 commit comments

Comments
 (0)