diff --git a/pandas/tests/test_errors.py b/pandas/tests/test_errors.py index 939ea8a64d94d..d72c00ceb0045 100644 --- a/pandas/tests/test_errors.py +++ b/pandas/tests/test_errors.py @@ -36,10 +36,9 @@ def test_exception_importable(exc): def test_catch_oob(): from pandas import errors - try: + msg = "Out of bounds nanosecond timestamp: 1500-01-01 00:00:00" + with pytest.raises(errors.OutOfBoundsDatetime, match=msg): pd.Timestamp("15000101") - except errors.OutOfBoundsDatetime: - pass class Foo: diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index 23c845f2b2795..3090343ba2fd9 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -46,13 +46,9 @@ def _assert_not_frame_equal(a, b, **kwargs): kwargs : dict The arguments passed to `tm.assert_frame_equal`. """ - try: + msg = "The two DataFrames were equal when they shouldn't have been" + with pytest.raises(AssertionError, match=msg): tm.assert_frame_equal(a, b, **kwargs) - msg = "The two DataFrames were equal when they shouldn't have been" - - pytest.fail(msg=msg) - except AssertionError: - pass def _assert_not_frame_equal_both(a, b, **kwargs):