Skip to content

Commit c15405b

Browse files
TST: Allow “no setter” messages from Python 3.11
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.
1 parent 61464f8 commit c15405b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pandas/tests/arrays/categorical/test_api.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_set_ordered(self):
5353
assert not cat2.ordered
5454

5555
# removed in 0.19.0
56-
msg = "can't set attribute"
56+
msg="can't set attribute|property .* of .* object has no setter"
5757
with pytest.raises(AttributeError, match=msg):
5858
cat.ordered = True
5959
with pytest.raises(AttributeError, match=msg):
@@ -507,7 +507,8 @@ def test_codes_immutable(self):
507507
tm.assert_numpy_array_equal(c.codes, exp)
508508

509509
# Assignments to codes should raise
510-
with pytest.raises(AttributeError, match="can't set attribute"):
510+
msg="can't set attribute|property .* of .* object has no setter"
511+
with pytest.raises(AttributeError, match=msg):
511512
c.codes = np.array([0, 1, 2, 0, 1], dtype="int8")
512513

513514
# changes in the codes array should raise

pandas/tests/indexes/multi/test_get_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_set_levels_codes_directly(idx):
139139
minor_codes = [(x + 1) % 1 for x in minor_codes]
140140
new_codes = [major_codes, minor_codes]
141141

142-
msg = "[Cc]an't set attribute"
142+
msg = "[Cc]an't set attribute|property .* of .* object has no setter"
143143
with pytest.raises(AttributeError, match=msg):
144144
idx.levels = new_levels
145145
with pytest.raises(AttributeError, match=msg):

pandas/tests/indexes/period/test_freq_attr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ def test_freq_setter_deprecated(self):
1717
idx.freq
1818

1919
# warning for setter
20-
with pytest.raises(AttributeError, match="can't set attribute"):
20+
msg="can't set attribute|property .* of .* object has no setter"
21+
with pytest.raises(AttributeError, match=msg):
2122
idx.freq = offsets.Day()

0 commit comments

Comments
 (0)