From d8c3502053f318679fb2949bc43d7225e1054e62 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Tue, 2 Aug 2022 01:29:08 -0400 Subject: [PATCH] =?UTF-8?q?TST:=20Allow=20=E2=80=9Cno=20setter=E2=80=9D=20?= =?UTF-8?q?messages=20from=20Python=203.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Loosen “can't set attribute” expected messages to also allow messages of the form “property … of … object has no setter”, fixing several assertion failures in the tests on Python 3.11. --- pandas/tests/arrays/categorical/test_api.py | 5 +++-- pandas/tests/indexes/multi/test_get_set.py | 2 +- pandas/tests/indexes/period/test_freq_attr.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/categorical/test_api.py b/pandas/tests/arrays/categorical/test_api.py index 87b1bb88aeac3..391a5e7e69ffe 100644 --- a/pandas/tests/arrays/categorical/test_api.py +++ b/pandas/tests/arrays/categorical/test_api.py @@ -53,7 +53,7 @@ def test_set_ordered(self): assert not cat2.ordered # removed in 0.19.0 - msg = "can't set attribute" + msg = "can't set attribute|property .* of .* object has no setter" with pytest.raises(AttributeError, match=msg): cat.ordered = True with pytest.raises(AttributeError, match=msg): @@ -507,7 +507,8 @@ def test_codes_immutable(self): tm.assert_numpy_array_equal(c.codes, exp) # Assignments to codes should raise - with pytest.raises(AttributeError, match="can't set attribute"): + msg = "can't set attribute|property .* of .* object has no setter" + with pytest.raises(AttributeError, match=msg): c.codes = np.array([0, 1, 2, 0, 1], dtype="int8") # changes in the codes array should raise diff --git a/pandas/tests/indexes/multi/test_get_set.py b/pandas/tests/indexes/multi/test_get_set.py index aa0e91cecd4fc..0ac3f0d2905a0 100644 --- a/pandas/tests/indexes/multi/test_get_set.py +++ b/pandas/tests/indexes/multi/test_get_set.py @@ -139,7 +139,7 @@ def test_set_levels_codes_directly(idx): minor_codes = [(x + 1) % 1 for x in minor_codes] new_codes = [major_codes, minor_codes] - msg = "[Cc]an't set attribute" + msg = "[Cc]an't set attribute|property .* of .* object has no setter" with pytest.raises(AttributeError, match=msg): idx.levels = new_levels with pytest.raises(AttributeError, match=msg): diff --git a/pandas/tests/indexes/period/test_freq_attr.py b/pandas/tests/indexes/period/test_freq_attr.py index 3bf3e700e5e72..7407effb22376 100644 --- a/pandas/tests/indexes/period/test_freq_attr.py +++ b/pandas/tests/indexes/period/test_freq_attr.py @@ -17,5 +17,6 @@ def test_freq_setter_deprecated(self): idx.freq # warning for setter - with pytest.raises(AttributeError, match="can't set attribute"): + msg = "can't set attribute|property .* of .* object has no setter" + with pytest.raises(AttributeError, match=msg): idx.freq = offsets.Day()