File tree 3 files changed +22
-1
lines changed 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
2.8.3.dev
2
2
---------
3
3
4
+ - fix #1035: collecting tests if test module level obj has __getattr__().
5
+ Thanks Suor for the report and Bruno Oliveira / Tom Viner for the PR.
4
6
5
7
2.8.2
6
8
-----
Original file line number Diff line number Diff line change 4
4
import functools
5
5
import py
6
6
import inspect
7
+ import types
7
8
import sys
8
9
import pytest
9
10
from _pytest .mark import MarkDecorator , MarkerError
@@ -43,6 +44,14 @@ def _format_args(func):
43
44
def _format_args (func ):
44
45
return inspect .formatargspec (* inspect .getargspec (func ))
45
46
47
+ if sys .version_info [:2 ] == (2 , 6 ):
48
+ def isclass (object ):
49
+ """ Return true if the object is a class. Overrides inspect.isclass for
50
+ python 2.6 because it will return True for objects which always return
51
+ something on __getattr__ calls (see #1035).
52
+ Backport of https://hg.python.org/cpython/rev/35bf8f7a8edc
53
+ """
54
+ return isinstance (object , (type , types .ClassType ))
46
55
47
56
def _has_positional_arg (func ):
48
57
return func .__code__ .co_argcount
@@ -2137,7 +2146,7 @@ def num_mock_patch_args(function):
2137
2146
2138
2147
def getfuncargnames (function , startindex = None ):
2139
2148
# XXX merge with main.py's varnames
2140
- #assert not inspect. isclass(function)
2149
+ #assert not isclass(function)
2141
2150
realfunction = function
2142
2151
while hasattr (realfunction , "__wrapped__" ):
2143
2152
realfunction = realfunction .__wrapped__
Original file line number Diff line number Diff line change @@ -95,6 +95,16 @@ def teardown_class(cls):
95
95
"*1 passed*" ,
96
96
])
97
97
98
+ def test_issue1035_obj_has_getattr (self , testdir ):
99
+ modcol = testdir .getmodulecol ("""
100
+ class Chameleon(object):
101
+ def __getattr__(self, name):
102
+ return True
103
+ chameleon = Chameleon()
104
+ """ )
105
+ colitems = modcol .collect ()
106
+ assert len (colitems ) == 0
107
+
98
108
99
109
class TestGenerator :
100
110
def test_generative_functions (self , testdir ):
You can’t perform that action at this time.
0 commit comments