question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TST: pytest.raises vs. tm.assert_raises_regex

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
gfyoungcommented, Nov 9, 2018

The deed has been done! See #23592.

1reaction
TomAugspurgercommented, Nov 8, 2018

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:

Also +1 for using pytest.raises now it has all functionality (I think?) we need.

For pytest.warns, maybe it would a good idea if somebody finds the time to ask pytest if they would be interested in adding such a feature.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pandas-dev/pandas/issues/16521#issuecomment-436990358, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQHIoEPmi7r0xtEAqmHJSUUK5p4SPgIks5utC7agaJpZM4NogdL .

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found