Skip to content

Commit

Permalink
Add @slow wrapper to avoid running slow tests.
Browse files Browse the repository at this point in the history
Use ./run_tests -f to only run the fast tests.
  • Loading branch information
nvie committed Feb 24, 2012
1 parent 91fff48 commit 844c5ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rq/timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __exit__(self, type, value, traceback):

# __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):
Expand Down
5 changes: 5 additions & 0 deletions run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -134,7 +134,8 @@ def test_cleaning_up_of_jobs(self):
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'

Expand Down

0 comments on commit 844c5ed

Please sign in to comment.