From 844c5ed8c7656cc7bdeaff3b7dfd3aa950bc04c7 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Fri, 24 Feb 2012 07:39:44 +0100 Subject: [PATCH] Add @slow wrapper to avoid running slow tests. Use ./run_tests -f to only run the fast tests. --- rq/timeouts.py | 4 ++-- run_tests | 5 +++++ tests/__init__.py | 12 ++++++++++++ tests/test_worker.py | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/rq/timeouts.py b/rq/timeouts.py index 83be1e6..72b827e 100644 --- a/rq/timeouts.py +++ b/rq/timeouts.py @@ -27,8 +27,8 @@ class death_pentalty_after(object): # __exit__ may return True to supress further exception handling. We # don't want to suppress any exceptions here, since all errors should - # just pass through, JobTimeoutException being handled as just one of - # them. + # just pass through, JobTimeoutException being handled normally to the + # invoking context. return False def handle_death_penalty(self, signum, frame): diff --git a/run_tests b/run_tests index 4ac4f7e..670b438 100755 --- a/run_tests +++ b/run_tests @@ -11,6 +11,11 @@ else safe_rg=cat fi +export ONLY_RUN_FAST_TESTS=1 +if [ "$1" == '-f' ]; then # Poor man's argparse + unset ONLY_RUN_FAST_TESTS +fi + if check_redis_running; then /usr/bin/env python -m unittest discover -v -s tests $@ 2>&1 | egrep -v '^test_' | $safe_rg else diff --git a/tests/__init__.py b/tests/__init__.py index 76895a4..2d54f29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,6 +15,18 @@ def find_empty_redis_database(): assert False, 'No empty Redis database found to run tests in.' +def slow(f): + import os + from functools import wraps + + @wraps(f) + def _inner(*args, **kwargs): + if os.environ.get('ONLY_RUN_FAST_TESTS'): + f(*args, **kwargs) + + return _inner + + class RQTestCase(unittest.TestCase): """Base class to inherit test cases from for RQ. diff --git a/tests/test_worker.py b/tests/test_worker.py index b1aa68c..92f177c 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -1,5 +1,5 @@ import os -from tests import RQTestCase +from tests import RQTestCase, slow from tests.fixtures import say_hello, div_by_zero, do_nothing, create_file, \ create_file_after_timeout from tests.helpers import strip_milliseconds @@ -134,7 +134,8 @@ class TestWorker(RQTestCase): assert self.testconn.exists(job_without_rv.key) == False - def test_timeouts(self): # noqa + @slow # noqa + def test_timeouts(self): """Worker kills jobs after timeout.""" sentinel_file = '/tmp/.rq_sentinel'