File tree 4 files changed +29
-4
lines changed 4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ David Díaz-Barquero
35
35
David Mohr
36
36
David Vierra
37
37
Diego Russo
38
+ Dmitry Dygalo
38
39
Edison Gustavo Muenz
39
40
Eduardo Schettino
40
41
Elizaveta Shashkova
Original file line number Diff line number Diff line change 51
51
* ImportErrors in plugins now are a fatal error instead of issuing a
52
52
pytest warning (`#1479 `_). Thanks to `@The-Compiler `_ for the PR.
53
53
54
+ * Fixed collection of classes with custom ``__new__ `` method.
55
+ Fixes `#1579 `_. Thanks to `@Stranger6667 `_ for the PR.
56
+
57
+ .. _#1579 : https://github.com/pytest-dev/pytest/issues/1579
54
58
.. _#1580 : https://github.com/pytest-dev/pytest/pull/1580
55
59
.. _#1605 : https://github.com/pytest-dev/pytest/issues/1605
56
60
.. _#1597 : https://github.com/pytest-dev/pytest/pull/1597
72
76
.. _@DRMacIver : https://github.com/DRMacIver
73
77
.. _@BeyondEvil : https://github.com/BeyondEvil
74
78
.. _@JonathonSonesen : https://github.com/JonathonSonesen
79
+ .. _@Stranger6667 : https://github.com/Stranger6667
75
80
76
81
77
82
2.9.2
Original file line number Diff line number Diff line change @@ -662,6 +662,10 @@ def collect(self):
662
662
self .warn ("C1" , "cannot collect test class %r because it has a "
663
663
"__init__ constructor" % self .obj .__name__ )
664
664
return []
665
+ elif hasnew (self .obj ):
666
+ self .warn ("C1" , "cannot collect test class %r because it has a "
667
+ "__new__ constructor" % self .obj .__name__ )
668
+ return []
665
669
return [self ._getcustomclass ("Instance" )(name = "()" , parent = self )]
666
670
667
671
def setup (self ):
@@ -679,8 +683,7 @@ def setup(self):
679
683
680
684
class Instance (PyCollector ):
681
685
def _getobj (self ):
682
- obj = self .parent .obj ()
683
- return obj
686
+ return self .parent .obj ()
684
687
685
688
def collect (self ):
686
689
self .session ._fixturemanager .parsefactories (self )
@@ -793,9 +796,13 @@ def getcallargs(self, obj):
793
796
def hasinit (obj ):
794
797
init = getattr (obj , '__init__' , None )
795
798
if init :
796
- if init != object .__init__ :
797
- return True
799
+ return init != object .__init__
800
+
798
801
802
+ def hasnew (obj ):
803
+ new = getattr (obj , '__new__' , None )
804
+ if new :
805
+ return new != object .__new__
799
806
800
807
801
808
def fillfixtures (function ):
Original file line number Diff line number Diff line change @@ -109,6 +109,18 @@ def __getattr__(self, name):
109
109
colitems = modcol .collect ()
110
110
assert len (colitems ) == 0
111
111
112
+ def test_issue1579_namedtuple (self , testdir ):
113
+ testdir .makepyfile ("""
114
+ import collections
115
+
116
+ TestCase = collections.namedtuple('TestCase', ['a'])
117
+ """ )
118
+ result = testdir .runpytest ('-rw' )
119
+ result .stdout .fnmatch_lines (
120
+ "*cannot collect test class 'TestCase' "
121
+ "because it has a __new__ constructor*"
122
+ )
123
+
112
124
113
125
class TestGenerator :
114
126
def test_generative_functions (self , testdir ):
You can’t perform that action at this time.
0 commit comments