From 1d1d1e63ff64b9adc65ca25a97412081f8739a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 20 Jan 2024 10:17:29 +0100 Subject: [PATCH 1/2] 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. --- pandas/tests/io/xml/test_xml.py | 8 +++++--- pandas/tests/tslibs/test_to_offset.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/xml/test_xml.py b/pandas/tests/io/xml/test_xml.py index 5451f7b2f16f5..0ee3ec85ab6c6 100644 --- a/pandas/tests/io/xml/test_xml.py +++ b/pandas/tests/io/xml/test_xml.py @@ -1361,7 +1361,8 @@ 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 " @@ -1369,8 +1370,9 @@ def test_empty_stylesheet(val): ) 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 diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index fd7fe819786a0..c2ce599d4a9a6 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -7,6 +7,7 @@ offsets, to_offset, ) +import pandas._testing as tm @pytest.mark.parametrize( @@ -194,7 +195,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) @@ -214,5 +215,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) From 82c4743c7dd9bb22fd102603ef7ac110b3af9bfa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:49:04 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/tslibs/test_to_offset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index c2ce599d4a9a6..ad4e9e2bcf38a 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -7,6 +7,7 @@ offsets, to_offset, ) + import pandas._testing as tm