Skip to content

Commit

Permalink
TST: Implement external error raised helper function. (pandas-dev#31130)
Browse files Browse the repository at this point in the history
@gfyoung wrote this function here
pandas-dev#30999 (comment)
so we can ignore error messages without breaking fututre CI tests of
bare pytest raises calls

Co-authored-by: gfyoung <gfyoung17+GitHub@gmail.com>

xref pandas-devgh-30999
  • Loading branch information
ShaharNaveh authored Feb 7, 2020
1 parent cf01369 commit 4b142ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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")

0 comments on commit 4b142ef

Please sign in to comment.