pytest.skip: Rename "msg" to "reason" for consistency with pytest.mark.skip/xfail?
See original GitHub issueThe signature of pytest.skip is:
skip(msg[, allow_module_level=False])
but the signature of pytest.xfail is:
xfail(reason='')
Marks (pytest.mark.skip, pytest.mark.skipif and pytest.mark.xfail) use reason too:
pytest.mark.skipif(condition, *, reason=None)
pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=False)¶
pytest.mark.skipif(condition, *, reason=None)¶
Note that pytest.fail uses msg:
fail(msg='', pytrace=True)
but at least from an user perspective, skip is probably closer to xfail and mark.skip / mark.skipif / mark.xfail.
Should we rename the msg argument for pytest.skip to reason for consistency (with a deprecation for the old name), or isn’t that worth the trouble?
Thanks to Francesco Casalegno for reporting this in the pytest training I gave at Europython 2021 today!
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
How to use skip and xfail to deal with tests that cannot succeed
The simplest way to skip a test function is to mark it with the skip decorator which may be passed an optional reason...
Read more >pytest Documentation - Read the Docs
2.13 How to use skip and xfail to deal with tests that cannot succeed . ... failure message. pytest only rewrites test modules...
Read more >Pytest - skip (xfail) mixed with parametrize - Stack Overflow
I added a @pytest.mark.incrementalparam to achieve this. ... be used without parametrize cause parametrize annotation creates automatically _genid variable.
Read more >pytest Changelog - pyup.io
signatures now accept a ``reason`` argument instead of ``msg``. ... This was changed for consistency with :func:`pytest.mark.skip <pytest.mark.skip>` and ...
Read more >Contributing to the code base - Pandas
This ensures a consistent error message when the dependency is not met. ... Use pytest.mark.skip when a test case is never expected to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks all, I will carve out some time tonight after work to attempt to unify
reason=across the board in places, I have made a start. After I have a few PRs i will look at initially creating follow up PRs to move plugins insidepytest-dev/usingmsg=explicitly to usereason=or pass w/o keyword.Some (naive) code searches:
pytest.fail(msg=: 15 on grep.app, 128 on Sourcegraph, 7 on Debian Code Searchpytest.skip(msg=: 45 on grep.app, 112 on Sourcegraph, 9 on Debian Code SearchPositional usage:
pytest.fail: 1121 on grep.app, 7.3k on Sourcegraph, 767 on Debian Code Searchpytest.skip: 3700 on grep.app, 25k on Sourcegraph, 2612 on Debian Code Search