Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Implement external error raised helper function. #31130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from shutil import rmtree
import string
import tempfile
from typing import Any, List, Optional, Union, cast
from typing import Any, Callable, List, Optional, Type, Union, cast
import warnings
import zipfile

Expand Down Expand Up @@ -2757,3 +2757,24 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
sep = os.linesep
expected = sep.join(rows_list) + sep
return expected


def external_error_raised(
expected_exception: Type[Exception],
) -> Callable[[Type[Exception], None], None]:
"""
Helper function to mark pytest.raises that have an external error message.

Parameters
----------
expected_exception : Exception
Expected error to raise.

Returns
-------
Callable
Regular `pytest.raises` function with `match` equal to `None`.
"""
import pytest

return pytest.raises(expected_exception, match=None)
5 changes: 5 additions & 0 deletions pandas/tests/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ def test_rng_context():
with tm.RNGContext(1):
assert np.random.randn() == expected1
assert np.random.randn() == expected0


def test_external_error_raised():
with tm.external_error_raised(TypeError):
raise TypeError("Should not check this error message, so it will pass")