Skip to content

Commit

Permalink
Update error message for module level skip to include 'allow_module_l…
Browse files Browse the repository at this point in the history
…evel' (pytest-dev#8906)

Co-authored-by: Naveen <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
  • Loading branch information
3 people authored and RonnyPfannschmidt committed Oct 1, 2021
1 parent d6db55d commit 79e8b02
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/8432.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`.
8 changes: 4 additions & 4 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
return mod
Expand Down
2 changes: 1 addition & 1 deletion testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 of a test will skip the entire module*"]
)


Expand Down

0 comments on commit 79e8b02

Please sign in to comment.