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:
|
if e.allow_module_level:
|
||||||
raise
|
raise
|
||||||
raise self.CollectError(
|
raise self.CollectError(
|
||||||
"Using pytest.skip outside of a test is not allowed. "
|
"Using pytest.skip outside of a test will skip the entire module. "
|
||||||
"To decorate a test function, use the @pytest.mark.skip "
|
"If that's your intention, pass `allow_module_level=True`. "
|
||||||
"or @pytest.mark.skipif decorators instead, and to skip a "
|
"If you want to skip a specific test or an entire class, "
|
||||||
"module use `pytestmark = pytest.mark.{skip,skipif}."
|
"use the @pytest.mark.skip or @pytest.mark.skipif decorators."
|
||||||
) from e
|
) from e
|
||||||
self.config.pluginmanager.consider_module(mod)
|
self.config.pluginmanager.consider_module(mod)
|
||||||
return mod
|
return mod
|
||||||
|
|
|
@ -1341,7 +1341,7 @@ def test_module_level_skip_error(pytester: Pytester) -> None:
|
||||||
)
|
)
|
||||||
result = pytester.runpytest()
|
result = pytester.runpytest()
|
||||||
result.stdout.fnmatch_lines(
|
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