1
+ import sys
2
+
1
3
import pytest
2
4
3
5
import env # noqa: F401
4
6
from pybind11_tests import ConstructorStats
5
7
from pybind11_tests import methods_and_attributes as m
6
8
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
+
7
16
8
17
def test_methods_and_attributes ():
9
18
instance1 = m .ExampleMandA ()
@@ -102,47 +111,47 @@ def test_properties():
102
111
103
112
with pytest .raises (AttributeError ) as excinfo :
104
113
dummy = instance .def_property_writeonly # unused var
105
- assert "unreadable attribute" in str (excinfo .value )
114
+ assert NO_GETTER_MSG in str (excinfo .value )
106
115
107
116
instance .def_property_writeonly = 4
108
117
assert instance .def_property_readonly == 4
109
118
110
119
with pytest .raises (AttributeError ) as excinfo :
111
120
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 )
113
122
114
123
with pytest .raises (AttributeError ) as excinfo :
115
124
instance .def_property_impossible = 5
116
- assert "can't set attribute" in str (excinfo .value )
125
+ assert NO_SETTER_MSG in str (excinfo .value )
117
126
118
127
119
128
def test_static_properties ():
120
129
assert m .TestProperties .def_readonly_static == 1
121
130
with pytest .raises (AttributeError ) as excinfo :
122
131
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 )
124
133
125
134
m .TestProperties .def_readwrite_static = 2
126
135
assert m .TestProperties .def_readwrite_static == 2
127
136
128
137
with pytest .raises (AttributeError ) as excinfo :
129
138
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 )
131
140
132
141
m .TestProperties .def_writeonly_static = 3
133
142
assert m .TestProperties .def_readonly_static == 3
134
143
135
144
assert m .TestProperties .def_property_readonly_static == 3
136
145
with pytest .raises (AttributeError ) as excinfo :
137
146
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 )
139
148
140
149
m .TestProperties .def_property_static = 4
141
150
assert m .TestProperties .def_property_static == 4
142
151
143
152
with pytest .raises (AttributeError ) as excinfo :
144
153
dummy = m .TestProperties .def_property_writeonly_static
145
- assert "unreadable attribute" in str (excinfo .value )
154
+ assert NO_GETTER_MSG in str (excinfo .value )
146
155
147
156
m .TestProperties .def_property_writeonly_static = 5
148
157
assert m .TestProperties .def_property_static == 5
@@ -160,7 +169,7 @@ def test_static_properties():
160
169
161
170
with pytest .raises (AttributeError ) as excinfo :
162
171
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 )
164
173
165
174
instance .def_property_writeonly_static = 4
166
175
assert instance .def_property_static == 4
0 commit comments