diff --git a/_pytest/python.py b/_pytest/python.py index 76fa2ddf7..d541dd4d3 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -229,10 +229,11 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj): "cannot collect %r because it is not a function." % name, ) return - if is_generator(obj): - return Generator(name, parent=collector) - else: - return list(collector._genfunctions(name, obj)) + if getattr(obj, "__test__", True): + if is_generator(obj): + return Generator(name, parent=collector) + else: + return list(collector._genfunctions(name, obj)) def is_generator(func): try: diff --git a/testing/python/integration.py b/testing/python/integration.py index e5764df9c..e27f27d52 100644 --- a/testing/python/integration.py +++ b/testing/python/integration.py @@ -225,6 +225,7 @@ class TestNoselikeTestAttribute: pass """) reprec = testdir.inline_run() + assert not reprec.getfailedcollections() calls = reprec.getreports("pytest_runtest_logreport") assert not calls @@ -233,7 +234,7 @@ class TestNoselikeTestAttribute: __test__ = True def test_func(): pass - test_hello.__test__ = False + test_func.__test__ = False class TestSome: __test__ = False @@ -241,6 +242,7 @@ class TestNoselikeTestAttribute: pass """) reprec = testdir.inline_run() + assert not reprec.getfailedcollections() calls = reprec.getreports("pytest_runtest_logreport") assert not calls @@ -256,6 +258,7 @@ class TestNoselikeTestAttribute: pass """) reprec = testdir.inline_run() + assert not reprec.getfailedcollections() call = reprec.getcalls("pytest_collection_modifyitems")[0] assert len(call.items) == 1 assert call.items[0].cls.__name__ == "TC"