unittest.UnitTestCase: Allow __test__ for methods
__test__ needs to be checked for methods of a class too. Earlier, this was not done, and all methods in a class was assumed to be a test. This commit adds the appropriate condition to ensure that if the __test__ is set to False, it does not collect that method. Fixes https://github.com/pytest-dev/pytest/issues/1558
This commit is contained in:
parent
6cc56b4a1b
commit
d4c9fa9f1a
1
AUTHORS
1
AUTHORS
|
@ -3,6 +3,7 @@ merlinux GmbH, Germany, office at merlinux eu
|
||||||
|
|
||||||
Contributors include::
|
Contributors include::
|
||||||
|
|
||||||
|
Abdeali JK
|
||||||
Abhijeet Kasurde
|
Abhijeet Kasurde
|
||||||
Anatoly Bubenkoff
|
Anatoly Bubenkoff
|
||||||
Andreas Zeidler
|
Andreas Zeidler
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
**New Features**
|
**New Features**
|
||||||
|
|
||||||
|
* Support nose-style ``__test__`` attribute on methods of classes,
|
||||||
|
including unittest-style Classes. If set to False, the test will not be
|
||||||
|
collected.
|
||||||
|
|
||||||
* New ``doctest_namespace`` fixture for injecting names into the
|
* New ``doctest_namespace`` fixture for injecting names into the
|
||||||
namespace in which your doctests run.
|
namespace in which your doctests run.
|
||||||
Thanks `@milliams`_ for the complete PR (`#1428`_).
|
Thanks `@milliams`_ for the complete PR (`#1428`_).
|
||||||
|
|
|
@ -50,6 +50,8 @@ class UnitTestCase(pytest.Class):
|
||||||
foundsomething = False
|
foundsomething = False
|
||||||
for name in loader.getTestCaseNames(self.obj):
|
for name in loader.getTestCaseNames(self.obj):
|
||||||
x = getattr(self.obj, name)
|
x = getattr(self.obj, name)
|
||||||
|
if not getattr(x, '__test__', True):
|
||||||
|
continue
|
||||||
funcobj = getattr(x, 'im_func', x)
|
funcobj = getattr(x, 'im_func', x)
|
||||||
transfer_markers(funcobj, cls, module)
|
transfer_markers(funcobj, cls, module)
|
||||||
yield TestCaseFunction(name, parent=self)
|
yield TestCaseFunction(name, parent=self)
|
||||||
|
|
|
@ -735,3 +735,17 @@ def test_unittest_skip_issue1169(testdir):
|
||||||
*SKIP*[1]*skipping due to reasons*
|
*SKIP*[1]*skipping due to reasons*
|
||||||
*1 skipped*
|
*1 skipped*
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def test_class_method_containing_test_issue1558(testdir):
|
||||||
|
testdir.makepyfile(test_foo="""
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class MyTestCase(unittest.TestCase):
|
||||||
|
def test_should_run(self):
|
||||||
|
pass
|
||||||
|
def test_should_not_run(self):
|
||||||
|
pass
|
||||||
|
test_should_not_run.__test__ = False
|
||||||
|
""")
|
||||||
|
reprec = testdir.inline_run()
|
||||||
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
Loading…
Reference in New Issue