Skip to content

Commit 4b142ef

Browse files
authored
TST: Implement external error raised helper function. (#31130)
@gfyoung wrote this function here #30999 (comment) so we can ignore error messages without breaking fututre CI tests of bare pytest raises calls Co-authored-by: gfyoung <[email protected]> xref gh-30999
1 parent cf01369 commit 4b142ef

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pandas/_testing.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from shutil import rmtree
99
import string
1010
import tempfile
11-
from typing import Any, List, Optional, Union, cast
11+
from typing import Any, Callable, List, Optional, Type, Union, cast
1212
import warnings
1313
import zipfile
1414

@@ -2757,3 +2757,24 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
27572757
sep = os.linesep
27582758
expected = sep.join(rows_list) + sep
27592759
return expected
2760+
2761+
2762+
def external_error_raised(
2763+
expected_exception: Type[Exception],
2764+
) -> Callable[[Type[Exception], None], None]:
2765+
"""
2766+
Helper function to mark pytest.raises that have an external error message.
2767+
2768+
Parameters
2769+
----------
2770+
expected_exception : Exception
2771+
Expected error to raise.
2772+
2773+
Returns
2774+
-------
2775+
Callable
2776+
Regular `pytest.raises` function with `match` equal to `None`.
2777+
"""
2778+
import pytest
2779+
2780+
return pytest.raises(expected_exception, match=None)

pandas/tests/util/test_util.py

+5
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ def test_rng_context():
7676
with tm.RNGContext(1):
7777
assert np.random.randn() == expected1
7878
assert np.random.randn() == expected0
79+
80+
81+
def test_external_error_raised():
82+
with tm.external_error_raised(TypeError):
83+
raise TypeError("Should not check this error message, so it will pass")

0 commit comments

Comments
 (0)