File tree 2 files changed +26
-5
lines changed 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -188,18 +188,21 @@ def pytest_pycollect_makemodule(path, parent):
188
188
return Module (path , parent )
189
189
190
190
191
+ def _safe_isclass (obj ):
192
+ try :
193
+ return isclass (obj )
194
+ except Exception :
195
+ return False
196
+
197
+
191
198
@hookimpl (hookwrapper = True )
192
199
def pytest_pycollect_makeitem (collector , name , obj ):
193
200
outcome = yield
194
201
res = outcome .get_result ()
195
202
if res is not None :
196
203
return
197
204
# nothing was collected elsewhere, let's do it here
198
- try :
199
- is_class = isclass (obj )
200
- except Exception :
201
- is_class = False
202
- if is_class :
205
+ if _safe_isclass (obj ):
203
206
if collector .istestclass (obj , name ):
204
207
Class = collector ._getcustomclass ("Class" )
205
208
outcome .force_result (Class (name , parent = collector ))
Original file line number Diff line number Diff line change @@ -1004,3 +1004,21 @@ def test_1():
1004
1004
result = testdir .runpytest ()
1005
1005
assert result .ret == 0
1006
1006
result .stdout .fnmatch_lines (["*1 passed in*" ])
1007
+
1008
+
1009
+ def test__safe_isclass ():
1010
+ from _pytest .python import _safe_isclass
1011
+
1012
+ assert _safe_isclass (type ) is True
1013
+
1014
+ # Simulates Django's django.conf.settings.
1015
+ class ImproperlyConfigured (Exception ):
1016
+ pass
1017
+
1018
+ class RaisesOnGetAttr (object ):
1019
+ def raises (self ):
1020
+ raise ImproperlyConfigured
1021
+
1022
+ __class__ = property (raises )
1023
+
1024
+ assert _safe_isclass (RaisesOnGetAttr ()) is False
You can’t perform that action at this time.
0 commit comments