TST: pytest.raises vs. tm.assert_raises_regex
See original GitHub issueI’m wondering whether we should explicitly say in the docs that we prefer tm.assert_raises_regex
over pytest.raises
unless there is no error message to provide. The former is a lot more informative from a dev-perspective as to why certain code should fail.
Thoughts?
(If we can agree that we do prefer the former, I also move to convert some of the tests to use tm.assert_raises_regex
instead of pytest.raises
).
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
How to write and report assertions in tests - Pytest
raises () is likely to be better for cases where you are testing exceptions your own code is deliberately raising, whereas using @pytest.mark.xfail...
Read more >How to properly assert that an exception gets raised in pytest?
raises is likely to be better for cases where you are testing exceptions your own code is deliberately raising, whereas using @pytest.mark.xfail ...
Read more >unittest — Unit testing framework — Python 3.11.1 ...
The crux of each test is a call to assertEqual() to check for an expected result; assertTrue() or assertFalse() to verify a condition;...
Read more >Replace pytest.raises with self.assertRaisesRegex · Issue #3808
Personally, I prefer pytest and would encourage people to write pytest style tests. There are some cool things like test parametrization, that ...
Read more >Assertions About Exceptions With Pytest.raises() - PyBites
pytest.raises() as a Context Manager. We can uses pytest.raises() to assert that a block of code raises a specific exception.
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 FreeTop 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
Top GitHub Comments
The deed has been done! See #23592.
Opened https://github.com/pytest-dev/pytest/issues/4343 upstream in pytest.
On Thu, Nov 8, 2018 at 7:17 AM Joris Van den Bossche < notifications@github.com> wrote: