From 2637326782cf308c55dd40e26b4bd35e20604eb2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 22 Oct 2012 19:22:01 +0200 Subject: [PATCH] improve support for trial a bit more: don't run trial's empty TestCase.runTest() method --- CHANGELOG | 3 +++ _pytest/__init__.py | 2 +- _pytest/unittest.py | 7 +++++-- doc/en/faq.txt | 11 +++++++---- setup.py | 2 +- testing/test_unittest.py | 24 ++++++++++++++++++++++-- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 95b62c08c..8905d86ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,9 @@ Changes between 2.3.1 and 2.3.2.dev - fix unittest behaviour: TestCase.runtest only called if there are test methods defined +- improve trial support: don't collect its empty + unittest.TestCase.runTest() method + - "python setup.py test" now works with pytest itself - fix/improve internal/packaging related bits: diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 337badd63..53adf449d 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.2.dev8' +__version__ = '2.3.2.dev9' diff --git a/_pytest/unittest.py b/_pytest/unittest.py index 982a6bc0d..c77b02736 100644 --- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -39,8 +39,11 @@ class UnitTestCase(pytest.Class): foundsomething = True if not foundsomething: - if getattr(self.obj, 'runTest', None) is not None: - yield TestCaseFunction('runTest', parent=self) + runtest = getattr(self.obj, 'runTest', None) + if runtest is not None: + ut = sys.modules.get("twisted.trial.unittest", None) + if ut is None or runtest != ut.TestCase.runTest: + yield TestCaseFunction('runTest', parent=self) def setup(self): meth = getattr(self.obj, 'setUpClass', None) diff --git a/doc/en/faq.txt b/doc/en/faq.txt index 8b7f4153f..daacc06fb 100644 --- a/doc/en/faq.txt +++ b/doc/en/faq.txt @@ -25,10 +25,13 @@ how does py.test relate to twisted's trial? Since some time py.test has builtin support for supporting tests written using trial. It does not itself start a reactor, however, -and does not handle Deferreds returned from a test. Someone using -these features might eventually write a dedicated ``pytest-twisted`` -plugin which will surely see strong support from the pytest development -team. +and does not handle Deferreds returned from a test in pytest style. +If you are using trial's unittest.TestCase chances are that you can +just run your tests even if you return Deferreds. In addition, +there also is a dedicated `pytest-twisted +