Make the runTest argument actually work.

This commit is contained in:
Jonathan Lange
2010-10-17 16:05:09 +01:00
parent d33a9f9055
commit 2692fd4757
2 changed files with 27 additions and 1 deletions

View File

@@ -86,6 +86,7 @@ class TestCase(unittest.TestCase):
supplied testtools.runtest.RunTest is used. The instance to be
used is created when run() is invoked, so will be fresh each time.
"""
runTest = kwargs.pop('runTest', RunTest)
unittest.TestCase.__init__(self, *args, **kwargs)
self._cleanups = []
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
# TestCase is safe to use with clone_test_with_new_id.
self.__details = None
self.__RunTest = kwargs.get('runTest', RunTest)
self.__RunTest = runTest
self.__exception_handlers = []
self.exception_handlers = [
(self.skipException, self._report_skip),

View File

@@ -8,6 +8,7 @@ from testtools import (
TestCase,
TestResult,
)
from testtools.matchers import Is
from testtools.tests.helpers import ExtendedTestResult
@@ -176,6 +177,30 @@ class TestRunTest(TestCase):
], 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():
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)