[Pytest-commit] commit/pytest: bubenkoff: Merged in hpk42/pytest-hpk/nose_test_attr (pull request #154)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Apr 10 22:38:57 CEST 2014
1 new commit in pytest:
https://bitbucket.org/hpk42/pytest/commits/912a8874de47/
Changeset: 912a8874de47
User: bubenkoff
Date: 2014-04-10 22:38:53
Summary: Merged in hpk42/pytest-hpk/nose_test_attr (pull request #154)
support nose-style __test__ attribute to disable collection of test modules/classes/functions
Affected #: 5 files
diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -64,6 +64,10 @@
- fix issue443: fix skip examples to use proper comparison. Thanks Alex
Groenholm.
+- support nose-style ``__test__`` attribute on modules, classes and
+ functions, including unittest-style Classes. If set to False, the
+ test will not be collected.
+
2.5.2
-----------------------------------
diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -229,10 +229,11 @@
"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:
@@ -314,6 +315,9 @@
return True
def collect(self):
+ if not getattr(self.obj, "__test__", True):
+ return []
+
# NB. we avoid random getattrs and peek in the __dict__ instead
# (XXX originally introduced from a PyPy need, still true?)
dicts = [getattr(self.obj, '__dict__', {})]
diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 _pytest/unittest.py
--- a/_pytest/unittest.py
+++ b/_pytest/unittest.py
@@ -41,10 +41,12 @@
super(UnitTestCase, self).setup()
def collect(self):
+ cls = self.obj
+ if not getattr(cls, "__test__", True):
+ return
self.session._fixturemanager.parsefactories(self, unittest=True)
loader = py.std.unittest.TestLoader()
module = self.getparent(pytest.Module).obj
- cls = self.obj
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 doc/en/nose.txt
--- a/doc/en/nose.txt
+++ b/doc/en/nose.txt
@@ -25,6 +25,7 @@
* SkipTest exceptions and markers
* setup/teardown decorators
* yield-based tests and their setup
+* ``__test__`` attribute on modules/classes/functions
* general usage of nose utilities
Unsupported idioms / known issues
diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -165,6 +165,7 @@
assert names == ["test_one", "test_two", "test_three"]
def test_mock_double_patch_issue473(self, testdir):
+ pytest.importorskip("mock", "1.0.1")
testdir.makepyfile("""
from mock import patch
from pytest import mark
@@ -176,8 +177,8 @@
def test_simple_thing(self, mock_path, mock_getcwd):
pass
""")
- res = testdir.inline_run()
- res.assertoutcome(passed=1)
+ reprec = testdir.inline_run()
+ reprec.assertoutcome(passed=1)
class TestReRunTests:
@@ -214,3 +215,52 @@
def test_pytestconfig_is_session_scoped():
from _pytest.python import pytestconfig
assert pytestconfig._pytestfixturefunction.scope == "session"
+
+
+class TestNoselikeTestAttribute:
+ def test_module(self, testdir):
+ testdir.makepyfile("""
+ __test__ = False
+ def test_hello():
+ pass
+ """)
+ reprec = testdir.inline_run()
+ assert not reprec.getfailedcollections()
+ calls = reprec.getreports("pytest_runtest_logreport")
+ assert not calls
+
+ def test_class_and_method(self, testdir):
+ testdir.makepyfile("""
+ __test__ = True
+ def test_func():
+ pass
+ test_func.__test__ = False
+
+ class TestSome:
+ __test__ = False
+ def test_method(self):
+ pass
+ """)
+ reprec = testdir.inline_run()
+ assert not reprec.getfailedcollections()
+ calls = reprec.getreports("pytest_runtest_logreport")
+ assert not calls
+
+ def test_unittest_class(self, testdir):
+ testdir.makepyfile("""
+ import unittest
+ class TC(unittest.TestCase):
+ def test_1(self):
+ pass
+ class TC2(unittest.TestCase):
+ __test__ = False
+ def test_2(self):
+ 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"
+
+
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list