Skip to content

Commit 1d1d1e6

Browse files
committed
TST: test for warnings using tm.assert_produces_warning()
Fix tests that used `pytest.raises()` to check for warnings, to use `tm.assert_produces_warning()` 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 1d1d1e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-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 tm.assert_produces_warning(FutureWarning, match=msg):
1375+
read_xml(kml, stylesheet=val)
13741376

13751377

13761378
# ITERPARSE

pandas/tests/tslibs/test_to_offset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
offsets,
88
to_offset,
99
)
10+
import pandas._testing as tm
1011

1112

1213
@pytest.mark.parametrize(
@@ -194,7 +195,7 @@ def test_to_offset_lowercase_frequency_deprecated(freq_depr):
194195
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
195196
f"future version, please use '{freq_depr.upper()[1:]}' instead."
196197

197-
with pytest.raises(FutureWarning, match=depr_msg):
198+
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
198199
to_offset(freq_depr)
199200

200201

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

217-
with pytest.raises(FutureWarning, match=depr_msg):
218+
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
218219
to_offset(freq_depr)

0 commit comments

Comments
 (0)