Add a decorator for specifying the RunTest object to use.
This commit is contained in:
@@ -11,6 +11,7 @@ __all__ = [
|
|||||||
'MultipleExceptions',
|
'MultipleExceptions',
|
||||||
'MultiTestResult',
|
'MultiTestResult',
|
||||||
'PlaceHolder',
|
'PlaceHolder',
|
||||||
|
'run_tests_with',
|
||||||
'TestCase',
|
'TestCase',
|
||||||
'TestResult',
|
'TestResult',
|
||||||
'TextTestResult',
|
'TextTestResult',
|
||||||
@@ -33,6 +34,7 @@ from testtools.testcase import (
|
|||||||
PlaceHolder,
|
PlaceHolder,
|
||||||
TestCase,
|
TestCase,
|
||||||
clone_test_with_new_id,
|
clone_test_with_new_id,
|
||||||
|
run_tests_with,
|
||||||
skip,
|
skip,
|
||||||
skipIf,
|
skipIf,
|
||||||
skipUnless,
|
skipUnless,
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ __metaclass__ = type
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
'clone_test_with_new_id',
|
'clone_test_with_new_id',
|
||||||
'MultipleExceptions',
|
'MultipleExceptions',
|
||||||
'TestCase',
|
'run_tests_with',
|
||||||
'skip',
|
'skip',
|
||||||
'skipIf',
|
'skipIf',
|
||||||
'skipUnless',
|
'skipUnless',
|
||||||
|
'TestCase',
|
||||||
]
|
]
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
@@ -61,6 +62,13 @@ except ImportError:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def run_tests_with(test_runner):
|
||||||
|
def decorator(f):
|
||||||
|
f._run_tests_with = test_runner
|
||||||
|
return f
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
class MultipleExceptions(Exception):
|
class MultipleExceptions(Exception):
|
||||||
"""Represents many exceptions raised from some operation.
|
"""Represents many exceptions raised from some operation.
|
||||||
|
|
||||||
@@ -100,7 +108,8 @@ class TestCase(unittest.TestCase):
|
|||||||
# __details is lazy-initialized so that a constructed-but-not-run
|
# __details is lazy-initialized so that a constructed-but-not-run
|
||||||
# TestCase is safe to use with clone_test_with_new_id.
|
# TestCase is safe to use with clone_test_with_new_id.
|
||||||
self.__details = None
|
self.__details = None
|
||||||
self.__RunTest = runTest
|
test_method = self._get_test_method()
|
||||||
|
self.__RunTest = getattr(test_method, '_run_tests_with', runTest)
|
||||||
self.__exception_handlers = []
|
self.__exception_handlers = []
|
||||||
self.exception_handlers = [
|
self.exception_handlers = [
|
||||||
(self.skipException, self._report_skip),
|
(self.skipException, self._report_skip),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
from testtools import (
|
from testtools import (
|
||||||
ExtendedToOriginalDecorator,
|
ExtendedToOriginalDecorator,
|
||||||
|
run_tests_with,
|
||||||
RunTest,
|
RunTest,
|
||||||
TestCase,
|
TestCase,
|
||||||
TestResult,
|
TestResult,
|
||||||
@@ -206,6 +207,16 @@ class TestTestCaseSupportForRunTest(TestCase):
|
|||||||
from_run_test = case.run(result)
|
from_run_test = case.run(result)
|
||||||
self.assertThat(from_run_test, Is(CustomRunTest.marker))
|
self.assertThat(from_run_test, Is(CustomRunTest.marker))
|
||||||
|
|
||||||
|
def test_decorator_for_run_test(self):
|
||||||
|
class SomeCase(TestCase):
|
||||||
|
@run_tests_with(CustomRunTest)
|
||||||
|
def test_foo(self):
|
||||||
|
pass
|
||||||
|
result = TestResult()
|
||||||
|
case = SomeCase('test_foo')
|
||||||
|
from_run_test = case.run(result)
|
||||||
|
self.assertThat(from_run_test, Is(CustomRunTest.marker))
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
from unittest import TestLoader
|
from unittest import TestLoader
|
||||||
|
|||||||
Reference in New Issue
Block a user