Skip to content

Commit e72a837

Browse files
author
deathaxe
authored
Refactor condition_timeout default value handling (#242)
1. Add proper `__init__()` methods to pass `condition_timeout` argument to newly created instances. 2. Use `self.condition_timeout()` as default in `_wait_condition()` argument list. This adds a some more lines of code but is a more compliant solution for how to handle additional parameters for inherited classes.
1 parent 6b839a0 commit e72a837

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

unittesting/core/py33/runner.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ def defer(delay, callback, *args, **kwargs):
2020

2121
class DeferringTextTestRunner(TextTestRunner):
2222
"""This test runner runs tests in deferred slices."""
23-
condition_timeout = DEFAULT_CONDITION_TIMEOUT
23+
24+
def __init__(
25+
self,
26+
stream=None,
27+
descriptions=True,
28+
verbosity=1,
29+
failfast=False,
30+
buffer=False,
31+
resultclass=None,
32+
warnings=None,
33+
condition_timeout=DEFAULT_CONDITION_TIMEOUT,
34+
):
35+
super(DeferringTextTestRunner, self).__init__(
36+
stream, descriptions, verbosity, failfast, buffer, resultclass, warnings)
37+
self.condition_timeout = condition_timeout
2438

2539
def run(self, test):
2640
"""Run the given test case or test suite."""
@@ -88,10 +102,9 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
88102
def _wait_condition(
89103
deferred, condition,
90104
period=DEFAULT_CONDITION_POLL_TIME,
91-
timeout=None,
105+
timeout=self.condition_timeout,
92106
start_time=None
93107
):
94-
timeout = timeout or self.condition_timeout
95108
if start_time is None:
96109
start_time = time.time()
97110

unittesting/core/py38/runner.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,23 @@ def defer(delay, callback, *args, **kwargs):
2020

2121
class DeferringTextTestRunner(TextTestRunner):
2222
"""This test runner runs tests in deferred slices."""
23-
condition_timeout = DEFAULT_CONDITION_TIMEOUT
23+
24+
def __init__(
25+
self,
26+
stream=None,
27+
descriptions=True,
28+
verbosity=1,
29+
failfast=False,
30+
buffer=False,
31+
resultclass=None,
32+
warnings=None,
33+
*,
34+
condition_timeout=DEFAULT_CONDITION_TIMEOUT,
35+
**kwargs
36+
):
37+
super(DeferringTextTestRunner, self).__init__(
38+
stream, descriptions, verbosity, failfast, buffer, resultclass, warnings, **kwargs)
39+
self.condition_timeout = condition_timeout
2440

2541
def run(self, test):
2642
"""Run the given test case or test suite."""
@@ -87,10 +103,9 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
87103
def _wait_condition(
88104
deferred, condition,
89105
period=DEFAULT_CONDITION_POLL_TIME,
90-
timeout=None,
106+
timeout=self.condition_timeout,
91107
start_time=None
92108
):
93-
timeout = timeout or self.condition_timeout
94109
if start_time is None:
95110
start_time = time.time()
96111

unittesting/package.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ def unit_testing(self, stream, package, settings, cleanup_hooks=[]):
9191
if settings["legacy_runner"]:
9292
raise Exception("`legacy_runner=True` is deprecated.")
9393
testRunner = DeferringTextTestRunner(
94-
stream, verbosity=settings["verbosity"], failfast=settings['failfast'])
95-
testRunner.condition_timeout = settings["condition_timeout"]
94+
stream=stream,
95+
verbosity=settings["verbosity"],
96+
failfast=settings['failfast'],
97+
condition_timeout=settings["condition_timeout"]
98+
)
9699
else:
97100
self.verify_testsuite(tests)
98101
testRunner = TextTestRunner(stream, verbosity=settings["verbosity"], failfast=settings['failfast'])

0 commit comments

Comments
 (0)