File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1+ Show the test module being collected when emitting ``PytestCollectionWarning `` messages for
2+ test classes with ``__init__ `` and ``__new__ `` methods to make it easier to pin down the problem.
Original file line number Diff line number Diff line change @@ -720,15 +720,17 @@ def collect(self):
720720 self .warn (
721721 PytestCollectionWarning (
722722 "cannot collect test class %r because it has a "
723- "__init__ constructor" % self .obj .__name__
723+ "__init__ constructor (from: %s)"
724+ % (self .obj .__name__ , self .parent .nodeid )
724725 )
725726 )
726727 return []
727728 elif hasnew (self .obj ):
728729 self .warn (
729730 PytestCollectionWarning (
730731 "cannot collect test class %r because it has a "
731- "__new__ constructor" % self .obj .__name__
732+ "__new__ constructor (from: %s)"
733+ % (self .obj .__name__ , self .parent .nodeid )
732734 )
733735 )
734736 return []
Original file line number Diff line number Diff line change @@ -146,7 +146,24 @@ def __init__(self):
146146 result = testdir .runpytest ("-rw" )
147147 result .stdout .fnmatch_lines (
148148 [
149- "*cannot collect test class 'TestClass1' because it has a __init__ constructor"
149+ "*cannot collect test class 'TestClass1' because it has "
150+ "a __init__ constructor (from: test_class_with_init_warning.py)"
151+ ]
152+ )
153+
154+ def test_class_with_new_warning (self , testdir ):
155+ testdir .makepyfile (
156+ """
157+ class TestClass1(object):
158+ def __new__(self):
159+ pass
160+ """
161+ )
162+ result = testdir .runpytest ("-rw" )
163+ result .stdout .fnmatch_lines (
164+ [
165+ "*cannot collect test class 'TestClass1' because it has "
166+ "a __new__ constructor (from: test_class_with_new_warning.py)"
150167 ]
151168 )
152169
You can’t perform that action at this time.
0 commit comments