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:
Naveen-Pratap 2021-07-14 19:57:26 +05:30 committed by GitHub
parent 69356d20cf
commit febb978651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -0,0 +1 @@
Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`.

View File

@ -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

View File

@ -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*"]
)