Skip to content

CI: Catch importwarning _SixMetaPathImporter.find_spec #48278

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

Closed
wants to merge 10 commits into from
24 changes: 20 additions & 4 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from pandas.compat import (
IS64,
PY310,
PY311,
is_numpy_dev,
is_platform_windows,
)
import pandas.util._test_decorators as td
Expand Down Expand Up @@ -3384,10 +3387,23 @@ def test_filepath_or_buffer_arg(
):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
elif encoding == "foo":
expected_warning = FutureWarning if method == "to_latex" else None
with tm.assert_produces_warning(expected_warning):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
if (
method == "to_string"
and data == "abc"
and filepath_or_buffer_id == "string"
and PY310
and not PY311
and not is_numpy_dev
):
# raises importwarning _SixMetaPathImporter.find_spec
with tm.assert_produces_warning(ImportWarning, check_stacklevel=False):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
else:
expected_warning = FutureWarning if method == "to_latex" else None
with tm.assert_produces_warning(expected_warning):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
else:
expected = getattr(df, method)()
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
Expand Down