Skip to content

TST: test for warnings using pytest.warns() #56974

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

Merged
merged 2 commits into from
Jan 23, 2024
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
8 changes: 5 additions & 3 deletions pandas/tests/io/xml/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,18 @@ def test_stylesheet_with_etree(kml_cta_rail_lines, xsl_flatten_doc):

@pytest.mark.parametrize("val", ["", b""])
def test_empty_stylesheet(val):
pytest.importorskip("lxml")
lxml_etree = pytest.importorskip("lxml.etree")

msg = (
"Passing literal xml to 'read_xml' is deprecated and "
"will be removed in a future version. To read from a "
"literal string, wrap it in a 'StringIO' object."
)
kml = os.path.join("data", "xml", "cta_rail_lines.kml")

with pytest.raises(FutureWarning, match=msg):
read_xml(kml, stylesheet=val)
with pytest.raises(lxml_etree.XMLSyntaxError):
with tm.assert_produces_warning(FutureWarning, match=msg):
read_xml(kml, stylesheet=val)


# ITERPARSE
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/tslibs/test_to_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
to_offset,
)

import pandas._testing as tm


@pytest.mark.parametrize(
"freq_input,expected",
Expand Down Expand Up @@ -194,7 +196,7 @@ def test_to_offset_lowercase_frequency_deprecated(freq_depr):
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
f"future version, please use '{freq_depr.upper()[1:]}' instead."

with pytest.raises(FutureWarning, match=depr_msg):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
to_offset(freq_depr)


Expand All @@ -214,5 +216,5 @@ def test_to_offset_uppercase_frequency_deprecated(freq_depr):
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
f"future version, please use '{freq_depr.lower()[1:]}' instead."

with pytest.raises(FutureWarning, match=depr_msg):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
to_offset(freq_depr)