Skip to content

Commit 85b7445

Browse files
TST: test for warnings using pytest.warns() (pandas-dev#56974)
* 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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 213e38e commit 85b7445

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pandas/tests/io/xml/test_xml.py

+5-3
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
to_offset,
99
)
1010

11+
import pandas._testing as tm
12+
1113

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

197-
with pytest.raises(FutureWarning, match=depr_msg):
199+
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
198200
to_offset(freq_depr)
199201

200202

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

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

0 commit comments

Comments
 (0)