Skip to content

Commit

Permalink
Add condition_timeout config option (#210)
Browse files Browse the repository at this point in the history
This commit adds a configuration option to limit the time to wait for test results of defered test cases.
  • Loading branch information
giampaolo authored Mar 17, 2024
1 parent 4c09769 commit e36563e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ UnitTesting could be configured by providing the following settings in `unittest
| generate_html_report | generate coverage report for coverage | false |
| capture_console | capture stdout and stderr in the test output | false |
| failfast | stop early if a test fails | false |
| condition_timeout | default timeout in ms for callables invoked via `yield` | 4000 |

## Others

Expand Down
4 changes: 3 additions & 1 deletion unittesting/core/py33/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def defer(delay, callback, *args, **kwargs):

class DeferringTextTestRunner(TextTestRunner):
"""This test runner runs tests in deferred slices."""
condition_timeout = DEFAULT_CONDITION_TIMEOUT

def run(self, test):
"""Run the given test case or test suite."""
Expand Down Expand Up @@ -87,9 +88,10 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
def _wait_condition(
deferred, condition,
period=DEFAULT_CONDITION_POLL_TIME,
timeout=DEFAULT_CONDITION_TIMEOUT,
timeout=None,
start_time=None
):
timeout = timeout or self.condition_timeout
if start_time is None:
start_time = time.time()

Expand Down
4 changes: 3 additions & 1 deletion unittesting/core/py38/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def defer(delay, callback, *args, **kwargs):

class DeferringTextTestRunner(TextTestRunner):
"""This test runner runs tests in deferred slices."""
condition_timeout = DEFAULT_CONDITION_TIMEOUT

def run(self, test):
"""Run the given test case or test suite."""
Expand Down Expand Up @@ -90,9 +91,10 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
def _wait_condition(
deferred, condition,
period=DEFAULT_CONDITION_POLL_TIME,
timeout=DEFAULT_CONDITION_TIMEOUT,
timeout=None,
start_time=None
):
timeout = timeout or self.condition_timeout
if start_time is None:
start_time = time.time()

Expand Down
3 changes: 2 additions & 1 deletion unittesting/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"coverage_on_worker_thread": False, # experimental
"generate_html_report": False,
"capture_console": False,
"failfast": False
"failfast": False,
"condition_timeout": 4000,
}


Expand Down
1 change: 1 addition & 0 deletions unittesting/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def unit_testing(self, stream, package, settings, cleanup_hooks=[]):
raise Exception("`legacy_runner=True` is deprecated.")
testRunner = DeferringTextTestRunner(
stream, verbosity=settings["verbosity"], failfast=settings['failfast'])
testRunner.condition_timeout = settings["condition_timeout"]
else:
self.verify_testsuite(tests)
testRunner = TextTestRunner(stream, verbosity=settings["verbosity"], failfast=settings['failfast'])
Expand Down

0 comments on commit e36563e

Please sign in to comment.