Deprecation of msg= for both pytest.skip() and pytest.fail(). (#8950)
* porting pytest.skip() to use reason=, adding tests * avoid adding **kwargs, it breaks other functionality, use optional msg= instead * deprecation of `pytest.fail(msg=...)` * fix bug with not capturing the returned reason value * pass reason= in acceptance async tests instead of msg= * finalising deprecations of `msg` in `pytest.skip()` and `pytest.fail()` * Update doc/en/deprecations.rst Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> * Update doc/en/deprecations.rst Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> * fix failing test after upstream merge * adding deprecation to `pytest.exit(msg=...)` * add docs for pytest.exit deprecations * finalising deprecation of msg for pytest.skip, pytest.exit and pytest.fail * hold a reference to the Scope instance to please mypy Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
@@ -200,6 +200,64 @@ def test_warns_none_is_deprecated():
|
||||
pass
|
||||
|
||||
|
||||
class TestSkipMsgArgumentDeprecated:
|
||||
def test_skip_with_msg_is_deprecated(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_skipping_msg():
|
||||
pytest.skip(msg="skippedmsg")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*PytestDeprecationWarning: pytest.skip(msg=...) is now deprecated, "
|
||||
"use pytest.skip(reason=...) instead",
|
||||
'*pytest.skip(msg="skippedmsg")*',
|
||||
]
|
||||
)
|
||||
result.assert_outcomes(skipped=1, warnings=1)
|
||||
|
||||
def test_fail_with_msg_is_deprecated(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_failing_msg():
|
||||
pytest.fail(msg="failedmsg")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*PytestDeprecationWarning: pytest.fail(msg=...) is now deprecated, "
|
||||
"use pytest.fail(reason=...) instead",
|
||||
'*pytest.fail(msg="failedmsg")',
|
||||
]
|
||||
)
|
||||
result.assert_outcomes(failed=1, warnings=1)
|
||||
|
||||
def test_exit_with_msg_is_deprecated(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_exit_msg():
|
||||
pytest.exit(msg="exitmsg")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*PytestDeprecationWarning: pytest.exit(msg=...) is now deprecated, "
|
||||
"use pytest.exit(reason=...) instead",
|
||||
]
|
||||
)
|
||||
result.assert_outcomes(warnings=1)
|
||||
|
||||
|
||||
def test_deprecation_of_cmdline_preparse(pytester: Pytester) -> None:
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
|
||||
@@ -70,7 +70,7 @@ def test_wrap_session_exit_sessionfinish(
|
||||
"""
|
||||
import pytest
|
||||
def pytest_sessionfinish():
|
||||
pytest.exit(msg="exit_pytest_sessionfinish", returncode={returncode})
|
||||
pytest.exit(reason="exit_pytest_sessionfinish", returncode={returncode})
|
||||
""".format(
|
||||
returncode=returncode
|
||||
)
|
||||
|
||||
@@ -1444,3 +1444,92 @@ def test_relpath_rootdir(pytester: Pytester) -> None:
|
||||
result.stdout.fnmatch_lines(
|
||||
["SKIPPED [[]1[]] tests/test_1.py:2: unconditional skip"]
|
||||
)
|
||||
|
||||
|
||||
def test_skip_using_reason_works_ok(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_skipping_reason():
|
||||
pytest.skip(reason="skippedreason")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.no_fnmatch_line("*PytestDeprecationWarning*")
|
||||
result.assert_outcomes(skipped=1)
|
||||
|
||||
|
||||
def test_fail_using_reason_works_ok(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_failing_reason():
|
||||
pytest.fail(reason="failedreason")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.no_fnmatch_line("*PytestDeprecationWarning*")
|
||||
result.assert_outcomes(failed=1)
|
||||
|
||||
|
||||
def test_fail_fails_with_msg_and_reason(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_fail_both_arguments():
|
||||
pytest.fail(reason="foo", msg="bar")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
"*UsageError: Passing both ``reason`` and ``msg`` to pytest.fail(...) is not permitted.*"
|
||||
)
|
||||
result.assert_outcomes(failed=1)
|
||||
|
||||
|
||||
def test_skip_fails_with_msg_and_reason(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_skip_both_arguments():
|
||||
pytest.skip(reason="foo", msg="bar")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
"*UsageError: Passing both ``reason`` and ``msg`` to pytest.skip(...) is not permitted.*"
|
||||
)
|
||||
result.assert_outcomes(failed=1)
|
||||
|
||||
|
||||
def test_exit_with_msg_and_reason_fails(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_exit_both_arguments():
|
||||
pytest.exit(reason="foo", msg="bar")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines(
|
||||
"*UsageError: cannot pass reason and msg to exit(), `msg` is deprecated, use `reason`.*"
|
||||
)
|
||||
result.assert_outcomes(failed=1)
|
||||
|
||||
|
||||
def test_exit_with_reason_works_ok(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def test_exit_reason_only():
|
||||
pytest.exit(reason="foo")
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(p)
|
||||
result.stdout.fnmatch_lines("*_pytest.outcomes.Exit: foo*")
|
||||
|
||||
Reference in New Issue
Block a user