I am working on a sensor API and dashboard application using Django 1.9 and Django Restframework.
I have the usual unit tests that should run when I call python manage.py test.
In addition, I have two different types of tests:
a) Test connectivity to upstream data sources and API's.
b) Data consistency tests.
While unit tests should run in any context, a) and b) depend on specific contexts. I would like to invoke them manually, when this contexts are available (or should be tested).
I don't want them to run (and fail) whenever I call the management test command.
Any suggestions, how to create a test runner that would exclude certain test folders by default but runs them when explicitly called.
You move context-dependent tests to separate app and exclude it. then implement this runner: TEST_RUNNER = 'testing.simple.AdvancedTestSuiteRunner'
from django.test.simple import DjangoTestSuiteRunner #@UnresolvedImport
import logging
from django.conf import settings
EXCLUDED_APPS = getattr(settings, 'TEST_EXCLUDE', [])
class AdvancedTestSuiteRunner(DjangoTestSuiteRunner):
def __init__(self, *args, **kwargs):
from django.conf import settings
settings.TESTING = True
south_log = logging.getLogger("south")
south_log.setLevel(logging.WARNING)
super(AdvancedTestSuiteRunner, self).__init__(*args, **kwargs)
def build_suite(self, *args, **kwargs):
suite = super(AdvancedTestSuiteRunner, self).build_suite(*args, **kwargs)
if not args[0] and not getattr(settings, 'RUN_ALL_TESTS', False):
tests = []
for case in suite:
pkg = case.__class__.__module__.split('.')[0]
if pkg not in EXCLUDED_APPS:
tests.append(case)
suite._tests = tests
return suite
When explicitly added to command, app won't be ignored 'python manage.py test south'
They have categories
@attr(speed='slow')
class MyTestCase:
def test_long_integration(self):
pass
def test_end_to_end_something(self):
pass
From docs
-a=ATTR, --attr=ATTR Run only tests that have attributes specified by ATTR [NOSE_ATTR]
-A=EXPR, --eval-attr=EXPR Run only tests for whose attributes the Python expression EXPR evaluates to True [NOSE_EVAL_ATTR]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With