Update error message for module level skip to include 'allow_module_level' (#8906)
Co-authored-by: Naveen <NaveenPr1@microland.com> Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
parent
69356d20cf
commit
febb978651
|
@ -0,0 +1 @@
|
|||
Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`.
|
|
@ -608,10 +608,10 @@ class Module(nodes.File, PyCollector):
|
|||
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
|
||||
|
|
|
@ -1341,7 +1341,7 @@ def test_module_level_skip_error(pytester: Pytester) -> None:
|
|||
)
|
||||
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*"]
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue