Add a decorator for specifying the RunTest object to use.
This commit is contained in:
@@ -11,6 +11,7 @@ __all__ = [
|
||||
'MultipleExceptions',
|
||||
'MultiTestResult',
|
||||
'PlaceHolder',
|
||||
'run_tests_with',
|
||||
'TestCase',
|
||||
'TestResult',
|
||||
'TextTestResult',
|
||||
@@ -33,6 +34,7 @@ from testtools.testcase import (
|
||||
PlaceHolder,
|
||||
TestCase,
|
||||
clone_test_with_new_id,
|
||||
run_tests_with,
|
||||
skip,
|
||||
skipIf,
|
||||
skipUnless,
|
||||
|
||||
@@ -6,10 +6,11 @@ __metaclass__ = type
|
||||
__all__ = [
|
||||
'clone_test_with_new_id',
|
||||
'MultipleExceptions',
|
||||
'TestCase',
|
||||
'run_tests_with',
|
||||
'skip',
|
||||
'skipIf',
|
||||
'skipUnless',
|
||||
'TestCase',
|
||||
]
|
||||
|
||||
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):
|
||||
"""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
|
||||
# TestCase is safe to use with clone_test_with_new_id.
|
||||
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.skipException, self._report_skip),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
from testtools import (
|
||||
ExtendedToOriginalDecorator,
|
||||
run_tests_with,
|
||||
RunTest,
|
||||
TestCase,
|
||||
TestResult,
|
||||
@@ -206,6 +207,16 @@ class TestTestCaseSupportForRunTest(TestCase):
|
||||
from_run_test = case.run(result)
|
||||
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():
|
||||
from unittest import TestLoader
|
||||
|
||||
Reference in New Issue
Block a user