mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Test without optional packages
Tox: * Add Tox factor for extras (all, none, individual ESP). For now, only break out ESPs that have specific extra dependencies (amazon_ses, sparkpost). * Install most package dependencies (including extras) through the package itself. * Use new runtests.py environment vars to limit test tags when Tox isn't installing all extras. Travis: * Rework matrix to request specific TOXENVs directly; drop tox-travis. Test runner (runtests.py): * Centralize RUN_LIVE_TESTS logic in runtests.py * Add ANYMAIL_ONLY_TEST and ANYMAIL_SKIP_TESTS env vars (comma-separated lists of tags) Test implementations: * Tag all ESP-specific tests with ESP * Tag live tests with "live" * Don't import ESP-specific packages at test module level. (Test discovery imports test modules before tag-based filtering.) Closes #104
This commit is contained in:
41
runtests.py
41
runtests.py
@@ -4,7 +4,9 @@
|
||||
# or
|
||||
# runtests.py [tests.test_x tests.test_y.SomeTestCase ...]
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
from distutils.util import strtobool
|
||||
|
||||
import django
|
||||
import os
|
||||
@@ -17,6 +19,18 @@ def setup_and_run_tests(test_labels=None):
|
||||
"""Discover and run project tests. Returns number of failures."""
|
||||
test_labels = test_labels or ['tests']
|
||||
|
||||
tags = envlist('ANYMAIL_ONLY_TEST')
|
||||
exclude_tags = envlist('ANYMAIL_SKIP_TESTS')
|
||||
|
||||
# In automated testing, don't run live tests unless specifically requested
|
||||
if envbool('CONTINUOUS_INTEGRATION') and not envbool('RUN_LIVE_TESTS'):
|
||||
exclude_tags.append('live')
|
||||
|
||||
if tags:
|
||||
print("Only running tests tagged: %r" % tags)
|
||||
if exclude_tags:
|
||||
print("Excluding tests tagged: %r" % exclude_tags)
|
||||
|
||||
warnings.simplefilter('default') # show DeprecationWarning and other default-ignored warnings
|
||||
|
||||
# noinspection PyStringFormat
|
||||
@@ -25,7 +39,7 @@ def setup_and_run_tests(test_labels=None):
|
||||
django.setup()
|
||||
|
||||
TestRunner = get_runner(settings)
|
||||
test_runner = TestRunner(verbosity=1)
|
||||
test_runner = TestRunner(verbosity=1, tags=tags, exclude_tags=exclude_tags)
|
||||
return test_runner.run_tests(test_labels)
|
||||
|
||||
|
||||
@@ -36,5 +50,30 @@ def runtests(test_labels=None):
|
||||
sys.exit(bool(failures))
|
||||
|
||||
|
||||
def envbool(var, default=False):
|
||||
"""Returns value of environment variable var as a bool, or default if not set.
|
||||
|
||||
Converts `'true'` to `True`, and `'false'` to `False`.
|
||||
See :func:`~distutils.util.strtobool` for full list of allowable values.
|
||||
"""
|
||||
val = os.getenv(var, None)
|
||||
if val is None:
|
||||
return default
|
||||
else:
|
||||
return strtobool(val)
|
||||
|
||||
|
||||
def envlist(var):
|
||||
"""Returns value of environment variable var split in a comma-separated list.
|
||||
|
||||
Returns an empty list if variable is empty or not set.
|
||||
"""
|
||||
val = os.getenv(var, "").split(',')
|
||||
if val == ['']:
|
||||
# "Splitting an empty string with a specified separator returns ['']"
|
||||
val = []
|
||||
return val
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
runtests(test_labels=sys.argv[1:])
|
||||
|
||||
Reference in New Issue
Block a user