diff options
author | David Douard <david.douard@logilab.fr> | 2014-11-28 00:16:44 +0100 |
---|---|---|
committer | David Douard <david.douard@logilab.fr> | 2014-11-28 00:16:44 +0100 |
commit | 8606c33284a5577199da49e10f15b3880dd90147 (patch) | |
tree | b4c25f4c39fda95c20fea5fe0591b6aebfa953e2 | |
parent | d06bab438fd83ca1cd2326aeeba4729144765a2b (diff) | |
download | logilab-common-8606c33284a5577199da49e10f15b3880dd90147.tar.gz |
[pytest] fix TestSuite.run wrapper (closes #280806)
_ts_wrapped_run is a modified version of the upstream
unittest.suite.TestSuite.run method,
but the recent (python 2.7) evolutions of this later had never been 'integrated'
in lgc.
This mismatch broke tests using a tearDownModule function.
This patch is... humm, sorry...
-rw-r--r-- | pytest.py | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -1082,8 +1082,14 @@ class NonStrictTestLoader(unittest.TestLoader): testCaseClass) return [testname for testname in testnames if not is_skipped(testname)] + +# The 2 functions below are modified versions of the TestSuite.run method +# that is provided with unittest2 for python 2.6, in unittest2/suite.py +# It is used to monkeypatch the original implementation to support +# extra runcondition and options arguments (see in testlib.py) + def _ts_run(self, result, runcondition=None, options=None): - self._wrapped_run(result,runcondition=runcondition, options=options) + self._wrapped_run(result, runcondition=runcondition, options=options) self._tearDownPreviousClass(None, result) self._handleModuleTearDown(result) return result @@ -1097,10 +1103,17 @@ def _ts_wrapped_run(self, result, debug=False, runcondition=None, options=None): self._handleModuleFixture(test, result) self._handleClassSetUp(test, result) result._previousTestClass = test.__class__ - if (getattr(test.__class__, '_classSetupFailed', False) or + if (getattr(test.__class__, '_classSetupFailed', False) or getattr(result, '_moduleSetUpFailed', False)): continue + # --- modifications to deal with _wrapped_run --- + # original code is: + # + # if not debug: + # test(result) + # else: + # test.debug() if hasattr(test, '_wrapped_run'): try: test._wrapped_run(result, debug, runcondition=runcondition, options=options) @@ -1113,6 +1126,25 @@ def _ts_wrapped_run(self, result, debug=False, runcondition=None, options=None): test(result) else: test.debug() + # --- end of modifications to deal with _wrapped_run --- + return result + +if sys.version_info >= (2, 7): + # The function below implements a modified version of the + # TestSuite.run method that is provided with python 2.7, in + # unittest/suite.py + def _ts_run(self, result, debug=False, runcondition=None, options=None): + topLevel = False + if getattr(result, '_testRunEntered', False) is False: + result._testRunEntered = topLevel = True + + self._wrapped_run(result, debug, runcondition, options) + + if topLevel: + self._tearDownPreviousClass(None, result) + self._handleModuleTearDown(result) + result._testRunEntered = False + return result def enable_dbc(*args): |