fix tests to properly fail on failed collectiosn (which was hiding an error)

and also implement __test__=False for test functions properly.

--HG--
branch : nose_test_attr
This commit is contained in:
holger krekel 2014-04-10 13:37:39 +02:00
parent e42cbc714f
commit 15af7e1662
2 changed files with 9 additions and 5 deletions

View File

@ -229,10 +229,11 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
"cannot collect %r because it is not a function." "cannot collect %r because it is not a function."
% name, ) % name, )
return return
if is_generator(obj): if getattr(obj, "__test__", True):
return Generator(name, parent=collector) if is_generator(obj):
else: return Generator(name, parent=collector)
return list(collector._genfunctions(name, obj)) else:
return list(collector._genfunctions(name, obj))
def is_generator(func): def is_generator(func):
try: try:

View File

@ -225,6 +225,7 @@ class TestNoselikeTestAttribute:
pass pass
""") """)
reprec = testdir.inline_run() reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
calls = reprec.getreports("pytest_runtest_logreport") calls = reprec.getreports("pytest_runtest_logreport")
assert not calls assert not calls
@ -233,7 +234,7 @@ class TestNoselikeTestAttribute:
__test__ = True __test__ = True
def test_func(): def test_func():
pass pass
test_hello.__test__ = False test_func.__test__ = False
class TestSome: class TestSome:
__test__ = False __test__ = False
@ -241,6 +242,7 @@ class TestNoselikeTestAttribute:
pass pass
""") """)
reprec = testdir.inline_run() reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
calls = reprec.getreports("pytest_runtest_logreport") calls = reprec.getreports("pytest_runtest_logreport")
assert not calls assert not calls
@ -256,6 +258,7 @@ class TestNoselikeTestAttribute:
pass pass
""") """)
reprec = testdir.inline_run() reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
call = reprec.getcalls("pytest_collection_modifyitems")[0] call = reprec.getcalls("pytest_collection_modifyitems")[0]
assert len(call.items) == 1 assert len(call.items) == 1
assert call.items[0].cls.__name__ == "TC" assert call.items[0].cls.__name__ == "TC"