Make the runTest argument actually work.
This commit is contained in:
@@ -86,6 +86,7 @@ class TestCase(unittest.TestCase):
|
|||||||
supplied testtools.runtest.RunTest is used. The instance to be
|
supplied testtools.runtest.RunTest is used. The instance to be
|
||||||
used is created when run() is invoked, so will be fresh each time.
|
used is created when run() is invoked, so will be fresh each time.
|
||||||
"""
|
"""
|
||||||
|
runTest = kwargs.pop('runTest', RunTest)
|
||||||
unittest.TestCase.__init__(self, *args, **kwargs)
|
unittest.TestCase.__init__(self, *args, **kwargs)
|
||||||
self._cleanups = []
|
self._cleanups = []
|
||||||
self._unique_id_gen = itertools.count(1)
|
self._unique_id_gen = itertools.count(1)
|
||||||
@@ -95,7 +96,7 @@ 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 = kwargs.get('runTest', RunTest)
|
self.__RunTest = runTest
|
||||||
self.__exception_handlers = []
|
self.__exception_handlers = []
|
||||||
self.exception_handlers = [
|
self.exception_handlers = [
|
||||||
(self.skipException, self._report_skip),
|
(self.skipException, self._report_skip),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from testtools import (
|
|||||||
TestCase,
|
TestCase,
|
||||||
TestResult,
|
TestResult,
|
||||||
)
|
)
|
||||||
|
from testtools.matchers import Is
|
||||||
from testtools.tests.helpers import ExtendedTestResult
|
from testtools.tests.helpers import ExtendedTestResult
|
||||||
|
|
||||||
|
|
||||||
@@ -176,6 +177,30 @@ class TestRunTest(TestCase):
|
|||||||
], result._events)
|
], result._events)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomRunTest(RunTest):
|
||||||
|
|
||||||
|
def __init__(self, marker, *args, **kwargs):
|
||||||
|
super(CustomRunTest, self).__init__(*args, **kwargs)
|
||||||
|
self._marker = marker
|
||||||
|
|
||||||
|
def run(self, result=None):
|
||||||
|
return self._marker
|
||||||
|
|
||||||
|
|
||||||
|
class TestTestCaseSupportForRunTest(TestCase):
|
||||||
|
|
||||||
|
def test_pass_custom_run_test(self):
|
||||||
|
class SomeCase(TestCase):
|
||||||
|
def test_foo(self):
|
||||||
|
pass
|
||||||
|
result = TestResult()
|
||||||
|
marker = object()
|
||||||
|
case = SomeCase(
|
||||||
|
'test_foo', runTest=lambda *args: CustomRunTest(marker, *args))
|
||||||
|
from_run_test = case.run(result)
|
||||||
|
self.assertThat(from_run_test, Is(marker))
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
from unittest import TestLoader
|
from unittest import TestLoader
|
||||||
return TestLoader().loadTestsFromName(__name__)
|
return TestLoader().loadTestsFromName(__name__)
|
||||||
|
|||||||
Reference in New Issue
Block a user