Skip to content

Commit 44b9f19

Browse files
committed
TST: test for warnings using pytest.warns()
Fix tests that used `pytest.raises()` to check for warnings, to use `pytest.warns()` instead. This is more correct, and it fixes running the test suite without `-Werror`. This is how Gentoo runs it, to avoid sudden test failures due to new deprecation warnings from upgraded dependencies.
1 parent 696d78c commit 44b9f19

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pandas/tests/io/xml/test_xml.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,16 +1361,18 @@ def test_stylesheet_with_etree(kml_cta_rail_lines, xsl_flatten_doc):
13611361

13621362
@pytest.mark.parametrize("val", ["", b""])
13631363
def test_empty_stylesheet(val):
1364-
pytest.importorskip("lxml")
1364+
lxml_etree = pytest.importorskip("lxml.etree")
1365+
13651366
msg = (
13661367
"Passing literal xml to 'read_xml' is deprecated and "
13671368
"will be removed in a future version. To read from a "
13681369
"literal string, wrap it in a 'StringIO' object."
13691370
)
13701371
kml = os.path.join("data", "xml", "cta_rail_lines.kml")
13711372

1372-
with pytest.raises(FutureWarning, match=msg):
1373-
read_xml(kml, stylesheet=val)
1373+
with pytest.raises(lxml_etree.XMLSyntaxError):
1374+
with pytest.warns(FutureWarning, match=msg):
1375+
read_xml(kml, stylesheet=val)
13741376

13751377

13761378
# ITERPARSE

pandas/tests/tslibs/test_to_offset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_to_offset_lowercase_frequency_deprecated(freq_depr):
194194
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
195195
f"future version, please use '{freq_depr.upper()[1:]}' instead."
196196

197-
with pytest.raises(FutureWarning, match=depr_msg):
197+
with pytest.warns(FutureWarning, match=depr_msg):
198198
to_offset(freq_depr)
199199

200200

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

217-
with pytest.raises(FutureWarning, match=depr_msg):
217+
with pytest.warns(FutureWarning, match=depr_msg):
218218
to_offset(freq_depr)

0 commit comments

Comments
 (0)