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..ad4e9e2bcf38a 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -8,6 +8,8 @@ to_offset, ) +import pandas._testing as tm + @pytest.mark.parametrize( "freq_input,expected", @@ -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) @@ -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)