@@ -29,7 +29,8 @@ def target():
2929
3030def load_implementation (name ):
3131 class mod :
32- type = name
32+ subclass = False
33+ kind = name
3334 if name == "slots" :
3435 from lazy_object_proxy .slots import Proxy
3536 elif name == "simple" :
@@ -56,17 +57,34 @@ class mod:
5657 "simple" ,
5758 # "external-django", "external-objproxies"
5859])
59- def lazy_object_proxy (request ):
60+ def lop_implementation (request ):
6061 return load_implementation (request .param )
6162
6263
63- def xfail_simple (test_func ):
64- from lazy_object_proxy .simple import Proxy
65- @wraps (test_func )
66- def xfail_wrapper (lazy_object_proxy ):
67- if lazy_object_proxy .Proxy is Proxy :
68- pytest .xfail (reason = "The lazy_object_proxy.simple.Proxy has some limitations." )
69- return xfail_wrapper
64+ @pytest .fixture (scope = "module" , params = [True , False ], ids = ['subclassed' , 'normal' ])
65+ def lop_subclass (request , lop_implementation ):
66+ if request .param :
67+ class submod (lop_implementation ):
68+ subclass = True
69+ Proxy = type ("SubclassOf_" + lop_implementation .Proxy .__name__ , (lop_implementation .Proxy ,), {})
70+ return submod
71+ else :
72+ return lop_implementation
73+
74+
75+ @pytest .fixture (scope = "function" )
76+ def lazy_object_proxy (request , lop_subclass ):
77+ if request .node .get_marker ('xfail_subclass' ):
78+ request .applymarker (pytest .mark .xfail (
79+ reason = "This test can't work because subclassing disables certain "
80+ "features like __doc__ and __module__ proxying."
81+ ))
82+ if request .node .get_marker ('xfail_simple' ):
83+ request .applymarker (pytest .mark .xfail (
84+ reason = "The lazy_object_proxy.simple.Proxy has some limitations."
85+ ))
86+
87+ return lop_subclass
7088
7189
7290def test_attributes (lazy_object_proxy ):
@@ -171,6 +189,7 @@ def test_class_object_qualname(lazy_object_proxy):
171189 assert wrapper .__qualname__ == __qualname__
172190
173191
192+ @pytest .mark .xfail_subclass
174193def test_class_module_name (lazy_object_proxy ):
175194 # Test preservation of class __module__ attribute.
176195
@@ -180,6 +199,7 @@ def test_class_module_name(lazy_object_proxy):
180199 assert wrapper .__module__ == target .__module__
181200
182201
202+ @pytest .mark .xfail_subclass
183203def test_class_doc_string (lazy_object_proxy ):
184204 # Test preservation of class __doc__ attribute.
185205
@@ -189,6 +209,7 @@ def test_class_doc_string(lazy_object_proxy):
189209 assert wrapper .__doc__ == target .__doc__
190210
191211
212+ @pytest .mark .xfail_subclass
192213def test_instance_module_name (lazy_object_proxy ):
193214 # Test preservation of instance __module__ attribute.
194215
@@ -198,6 +219,7 @@ def test_instance_module_name(lazy_object_proxy):
198219 assert wrapper .__module__ == target .__module__
199220
200221
222+ @pytest .mark .xfail_subclass
201223def test_instance_doc_string (lazy_object_proxy ):
202224 # Test preservation of instance __doc__ attribute.
203225
@@ -230,6 +252,7 @@ def test_function_object_qualname(lazy_object_proxy):
230252 assert wrapper .__qualname__ == __qualname__
231253
232254
255+ @pytest .mark .xfail_subclass
233256def test_function_module_name (lazy_object_proxy ):
234257 # Test preservation of function __module__ attribute.
235258
@@ -239,6 +262,7 @@ def test_function_module_name(lazy_object_proxy):
239262 assert wrapper .__module__ == target .__module__
240263
241264
265+ @pytest .mark .xfail_subclass
242266def test_function_doc_string (lazy_object_proxy ):
243267 # Test preservation of function __doc__ attribute.
244268
@@ -290,7 +314,7 @@ def test_dir_of_class(lazy_object_proxy):
290314
291315 assert dir (wrapper ) == dir (target )
292316
293- @xfail_simple
317+ @pytest . mark . xfail_simple
294318def test_vars_of_class (lazy_object_proxy ):
295319 # Test preservation of class __dir__ attribute.
296320
@@ -309,7 +333,7 @@ def test_dir_of_instance(lazy_object_proxy):
309333 assert dir (wrapper ) == dir (target )
310334
311335
312- @xfail_simple
336+ @pytest . mark . xfail_simple
313337def test_vars_of_instance (lazy_object_proxy ):
314338 # Test preservation of instance __dir__ attribute.
315339
@@ -328,7 +352,7 @@ def test_dir_of_function(lazy_object_proxy):
328352 assert dir (wrapper ) == dir (target )
329353
330354
331- @xfail_simple
355+ @pytest . mark . xfail_simple
332356def test_vars_of_function (lazy_object_proxy ):
333357 # Test preservation of function __dir__ attribute.
334358
@@ -1020,13 +1044,13 @@ def test_iadd(lazy_object_proxy):
10201044 value += 1
10211045 assert value == 2
10221046
1023- if lazy_object_proxy .type != 'simple' :
1047+ if lazy_object_proxy .kind != 'simple' :
10241048 assert type (value ) == lazy_object_proxy .Proxy
10251049
10261050 value += one
10271051 assert value == 3
10281052
1029- if lazy_object_proxy .type != 'simple' :
1053+ if lazy_object_proxy .kind != 'simple' :
10301054 assert type (value ) == lazy_object_proxy .Proxy
10311055
10321056
@@ -1036,13 +1060,13 @@ def test_isub(lazy_object_proxy):
10361060
10371061 value -= 1
10381062 assert value == 0
1039- if lazy_object_proxy .type != 'simple' :
1063+ if lazy_object_proxy .kind != 'simple' :
10401064 assert type (value ) == lazy_object_proxy .Proxy
10411065
10421066 value -= one
10431067 assert value == - 1
10441068
1045- if lazy_object_proxy .type != 'simple' :
1069+ if lazy_object_proxy .kind != 'simple' :
10461070 assert type (value ) == lazy_object_proxy .Proxy
10471071
10481072
@@ -1053,13 +1077,13 @@ def test_imul(lazy_object_proxy):
10531077 value *= 2
10541078 assert value == 4
10551079
1056- if lazy_object_proxy .type != 'simple' :
1080+ if lazy_object_proxy .kind != 'simple' :
10571081 assert type (value ) == lazy_object_proxy .Proxy
10581082
10591083 value *= two
10601084 assert value == 8
10611085
1062- if lazy_object_proxy .type != 'simple' :
1086+ if lazy_object_proxy .kind != 'simple' :
10631087 assert type (value ) == lazy_object_proxy .Proxy
10641088
10651089
@@ -1073,13 +1097,13 @@ def test_idiv(lazy_object_proxy):
10731097 value /= 2
10741098 assert value == 2 / 2
10751099
1076- if lazy_object_proxy .type != 'simple' :
1100+ if lazy_object_proxy .kind != 'simple' :
10771101 assert type (value ) == lazy_object_proxy .Proxy
10781102
10791103 value /= two
10801104 assert value == 2 / 2 / 2
10811105
1082- if lazy_object_proxy .type != 'simple' :
1106+ if lazy_object_proxy .kind != 'simple' :
10831107 assert type (value ) == lazy_object_proxy .Proxy
10841108
10851109
@@ -1090,13 +1114,13 @@ def test_ifloordiv(lazy_object_proxy):
10901114 value //= 2
10911115 assert value == 2 // 2
10921116
1093- if lazy_object_proxy .type != 'simple' :
1117+ if lazy_object_proxy .kind != 'simple' :
10941118 assert type (value ) == lazy_object_proxy .Proxy
10951119
10961120 value //= two
10971121 assert value == 2 // 2 // 2
10981122
1099- if lazy_object_proxy .type != 'simple' :
1123+ if lazy_object_proxy .kind != 'simple' :
11001124 assert type (value ) == lazy_object_proxy .Proxy
11011125
11021126
@@ -1107,13 +1131,13 @@ def test_imod(lazy_object_proxy):
11071131 value %= 2
11081132 assert value == 10 % 2
11091133
1110- if lazy_object_proxy .type != 'simple' :
1134+ if lazy_object_proxy .kind != 'simple' :
11111135 assert type (value ) == lazy_object_proxy .Proxy
11121136
11131137 value %= two
11141138 assert value == 10 % 2 % 2
11151139
1116- if lazy_object_proxy .type != 'simple' :
1140+ if lazy_object_proxy .kind != 'simple' :
11171141 assert type (value ) == lazy_object_proxy .Proxy
11181142
11191143
@@ -1124,13 +1148,13 @@ def test_ipow(lazy_object_proxy):
11241148 value **= 2
11251149 assert value == 10 ** 2
11261150
1127- if lazy_object_proxy .type != 'simple' :
1151+ if lazy_object_proxy .kind != 'simple' :
11281152 assert type (value ) == lazy_object_proxy .Proxy
11291153
11301154 value **= two
11311155 assert value == 10 ** 2 ** 2
11321156
1133- if lazy_object_proxy .type != 'simple' :
1157+ if lazy_object_proxy .kind != 'simple' :
11341158 assert type (value ) == lazy_object_proxy .Proxy
11351159
11361160
@@ -1141,13 +1165,13 @@ def test_ilshift(lazy_object_proxy):
11411165 value <<= 2
11421166 assert value == 256 << 2
11431167
1144- if lazy_object_proxy .type != 'simple' :
1168+ if lazy_object_proxy .kind != 'simple' :
11451169 assert type (value ) == lazy_object_proxy .Proxy
11461170
11471171 value <<= two
11481172 assert value == 256 << 2 << 2
11491173
1150- if lazy_object_proxy .type != 'simple' :
1174+ if lazy_object_proxy .kind != 'simple' :
11511175 assert type (value ) == lazy_object_proxy .Proxy
11521176
11531177
@@ -1158,13 +1182,13 @@ def test_irshift(lazy_object_proxy):
11581182 value >>= 2
11591183 assert value == 2 >> 2
11601184
1161- if lazy_object_proxy .type != 'simple' :
1185+ if lazy_object_proxy .kind != 'simple' :
11621186 assert type (value ) == lazy_object_proxy .Proxy
11631187
11641188 value >>= two
11651189 assert value == 2 >> 2 >> 2
11661190
1167- if lazy_object_proxy .type != 'simple' :
1191+ if lazy_object_proxy .kind != 'simple' :
11681192 assert type (value ) == lazy_object_proxy .Proxy
11691193
11701194
@@ -1175,13 +1199,13 @@ def test_iand(lazy_object_proxy):
11751199 value &= 2
11761200 assert value == 1 & 2
11771201
1178- if lazy_object_proxy .type != 'simple' :
1202+ if lazy_object_proxy .kind != 'simple' :
11791203 assert type (value ) == lazy_object_proxy .Proxy
11801204
11811205 value &= two
11821206 assert value == 1 & 2 & 2
11831207
1184- if lazy_object_proxy .type != 'simple' :
1208+ if lazy_object_proxy .kind != 'simple' :
11851209 assert type (value ) == lazy_object_proxy .Proxy
11861210
11871211
@@ -1192,13 +1216,13 @@ def test_ixor(lazy_object_proxy):
11921216 value ^= 2
11931217 assert value == 1 ^ 2
11941218
1195- if lazy_object_proxy .type != 'simple' :
1219+ if lazy_object_proxy .kind != 'simple' :
11961220 assert type (value ) == lazy_object_proxy .Proxy
11971221
11981222 value ^= two
11991223 assert value == 1 ^ 2 ^ 2
12001224
1201- if lazy_object_proxy .type != 'simple' :
1225+ if lazy_object_proxy .kind != 'simple' :
12021226 assert type (value ) == lazy_object_proxy .Proxy
12031227
12041228
@@ -1209,13 +1233,13 @@ def test_ior(lazy_object_proxy):
12091233 value |= 2
12101234 assert value == 1 | 2
12111235
1212- if lazy_object_proxy .type != 'simple' :
1236+ if lazy_object_proxy .kind != 'simple' :
12131237 assert type (value ) == lazy_object_proxy .Proxy
12141238
12151239 value |= two
12161240 assert value == 1 | 2 | 2
12171241
1218- if lazy_object_proxy .type != 'simple' :
1242+ if lazy_object_proxy .kind != 'simple' :
12191243 assert type (value ) == lazy_object_proxy .Proxy
12201244
12211245
0 commit comments