parametrize test_warn_missing for a cleaner test

This commit is contained in:
Gleb Nikonorov 2020-06-21 10:26:36 -04:00
parent fe68c58698
commit 33de350619
1 changed files with 26 additions and 19 deletions

View File

@ -1384,27 +1384,34 @@ def test_exception_handling_no_traceback(testdir):
@pytest.mark.skipif("'__pypy__' in sys.builtin_module_names") @pytest.mark.skipif("'__pypy__' in sys.builtin_module_names")
def test_warn_missing(testdir): @pytest.mark.parametrize(
testdir.makepyfile("") "cmdline_args, warning_output",
[
warning_output = [ (
"warning :*PytestConfigWarning:*assert statements are not executed*" ["-OO", "-m", "pytest", "-h"],
] ["warning :*PytestConfigWarning:*assert statements are not executed*"],
result = testdir.run(sys.executable, "-OO", "-m", "pytest", "-h") ),
result.stdout.fnmatch_lines(warning_output) (
["-OO", "-m", "pytest"],
warning_output = [ [
"=*= warnings summary =*=", "=*= warnings summary =*=",
"*PytestConfigWarning:*assert statements are not executed*", "*PytestConfigWarning:*assert statements are not executed*",
] ],
result = testdir.run(sys.executable, "-OO", "-m", "pytest") ),
result.stdout.fnmatch_lines(warning_output) (
["-OO", "-m", "pytest", "--assert=plain"],
warning_output = [ [
"=*= warnings summary =*=", "=*= warnings summary =*=",
"*PytestConfigWarning: ASSERTIONS ARE NOT EXECUTED and FAILING TESTS WILL PASS. Are you using python -O?", "*PytestConfigWarning: ASSERTIONS ARE NOT EXECUTED and FAILING TESTS WILL PASS. "
] "Are you using python -O?",
result = testdir.run(sys.executable, "-OO", "-m", "pytest", "--assert=plain") ],
),
],
)
def test_warn_missing(testdir, cmdline_args, warning_output):
testdir.makepyfile("")
result = testdir.run(sys.executable, *cmdline_args)
result.stdout.fnmatch_lines(warning_output) result.stdout.fnmatch_lines(warning_output)