Skip to content

Commit 99bafd0

Browse files
committed
fix: error message changed in 3.11
1 parent c781d29 commit 99bafd0

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tests/test_methods_and_attributes.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import sys
2+
13
import pytest
24

35
import env # noqa: F401
46
from pybind11_tests import ConstructorStats
57
from pybind11_tests import methods_and_attributes as m
68

9+
NO_GETTER_MSG = (
10+
"unreadable attribute" if sys.version_info < (3, 11) else "object has no getter"
11+
)
12+
NO_SETTER_MSG = (
13+
"can't set attribute" if sys.version_info < (3, 11) else "object has no setter"
14+
)
15+
716

817
def test_methods_and_attributes():
918
instance1 = m.ExampleMandA()
@@ -102,47 +111,47 @@ def test_properties():
102111

103112
with pytest.raises(AttributeError) as excinfo:
104113
dummy = instance.def_property_writeonly # unused var
105-
assert "unreadable attribute" in str(excinfo.value)
114+
assert NO_GETTER_MSG in str(excinfo.value)
106115

107116
instance.def_property_writeonly = 4
108117
assert instance.def_property_readonly == 4
109118

110119
with pytest.raises(AttributeError) as excinfo:
111120
dummy = instance.def_property_impossible # noqa: F841 unused var
112-
assert "unreadable attribute" in str(excinfo.value)
121+
assert NO_GETTER_MSG in str(excinfo.value)
113122

114123
with pytest.raises(AttributeError) as excinfo:
115124
instance.def_property_impossible = 5
116-
assert "can't set attribute" in str(excinfo.value)
125+
assert NO_SETTER_MSG in str(excinfo.value)
117126

118127

119128
def test_static_properties():
120129
assert m.TestProperties.def_readonly_static == 1
121130
with pytest.raises(AttributeError) as excinfo:
122131
m.TestProperties.def_readonly_static = 2
123-
assert "can't set attribute" in str(excinfo.value)
132+
assert NO_SETTER_MSG in str(excinfo.value)
124133

125134
m.TestProperties.def_readwrite_static = 2
126135
assert m.TestProperties.def_readwrite_static == 2
127136

128137
with pytest.raises(AttributeError) as excinfo:
129138
dummy = m.TestProperties.def_writeonly_static # unused var
130-
assert "unreadable attribute" in str(excinfo.value)
139+
assert NO_GETTER_MSG in str(excinfo.value)
131140

132141
m.TestProperties.def_writeonly_static = 3
133142
assert m.TestProperties.def_readonly_static == 3
134143

135144
assert m.TestProperties.def_property_readonly_static == 3
136145
with pytest.raises(AttributeError) as excinfo:
137146
m.TestProperties.def_property_readonly_static = 99
138-
assert "can't set attribute" in str(excinfo.value)
147+
assert NO_SETTER_MSG in str(excinfo.value)
139148

140149
m.TestProperties.def_property_static = 4
141150
assert m.TestProperties.def_property_static == 4
142151

143152
with pytest.raises(AttributeError) as excinfo:
144153
dummy = m.TestProperties.def_property_writeonly_static
145-
assert "unreadable attribute" in str(excinfo.value)
154+
assert NO_GETTER_MSG in str(excinfo.value)
146155

147156
m.TestProperties.def_property_writeonly_static = 5
148157
assert m.TestProperties.def_property_static == 5
@@ -160,7 +169,7 @@ def test_static_properties():
160169

161170
with pytest.raises(AttributeError) as excinfo:
162171
dummy = instance.def_property_writeonly_static # noqa: F841 unused var
163-
assert "unreadable attribute" in str(excinfo.value)
172+
assert NO_GETTER_MSG in str(excinfo.value)
164173

165174
instance.def_property_writeonly_static = 4
166175
assert instance.def_property_static == 4

0 commit comments

Comments
 (0)