Show test module in the PytestCollectionWarning message
Related to #5330
This commit is contained in:
parent
72fc43952b
commit
5cbc06a453
|
@ -0,0 +1,2 @@
|
||||||
|
Show the test module being collected when emitting ``PytestCollectionWarning`` messages for
|
||||||
|
test classes with ``__init__`` and ``__new__`` methods to make it easier to pin down the problem.
|
|
@ -720,7 +720,8 @@ class Class(PyCollector):
|
||||||
self.warn(
|
self.warn(
|
||||||
PytestCollectionWarning(
|
PytestCollectionWarning(
|
||||||
"cannot collect test class %r because it has a "
|
"cannot collect test class %r because it has a "
|
||||||
"__init__ constructor" % self.obj.__name__
|
"__init__ constructor (from: %s)"
|
||||||
|
% (self.obj.__name__, self.parent.nodeid)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return []
|
return []
|
||||||
|
@ -728,7 +729,8 @@ class Class(PyCollector):
|
||||||
self.warn(
|
self.warn(
|
||||||
PytestCollectionWarning(
|
PytestCollectionWarning(
|
||||||
"cannot collect test class %r because it has a "
|
"cannot collect test class %r because it has a "
|
||||||
"__new__ constructor" % self.obj.__name__
|
"__new__ constructor (from: %s)"
|
||||||
|
% (self.obj.__name__, self.parent.nodeid)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -146,7 +146,24 @@ class TestClass(object):
|
||||||
result = testdir.runpytest("-rw")
|
result = testdir.runpytest("-rw")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"*cannot collect test class 'TestClass1' because it has a __init__ constructor"
|
"*cannot collect test class 'TestClass1' because it has "
|
||||||
|
"a __init__ constructor (from: test_class_with_init_warning.py)"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_class_with_new_warning(self, testdir):
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
class TestClass1(object):
|
||||||
|
def __new__(self):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("-rw")
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"*cannot collect test class 'TestClass1' because it has "
|
||||||
|
"a __new__ constructor (from: test_class_with_new_warning.py)"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue