Skip to content

Commit

Permalink
Alter the runtests.py script to just call py.test (keep it simple)
Browse files Browse the repository at this point in the history
travis: Run py.test --cov=oscar instead of coverage run
  • Loading branch information
mvantellingen committed Jul 13, 2016
1 parent bc893aa commit db2a9d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 82 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ docs:
cd docs && make html

coverage:
coverage run ./runtests.py --with-xunit
coverage xml -i
py.test --cov=oscar --cov-report=term-missing

lint:
./lint.sh
Expand Down
82 changes: 2 additions & 80 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,8 @@
#!/usr/bin/env python
"""
Custom test runner
If args or options, we run the testsuite as quickly as possible.
If args but no options, we default to using the spec plugin and aborting on
first error/failure.
If options, we ignore defaults and pass options onto pytest.
Examples:
Run all tests (as fast as possible)
$ ./runtests.py
Run all unit tests (using spec output)
$ ./runtests.py tests/unit
Run all checkout unit tests (using spec output)
$ ./runtests.py tests/unit/checkout
Re-run failing tests (requires pytest-cache)
$ ./runtests.py ... --lf
Drop into pdb when a test fails
$ ./runtests.py ... --pdb
"""

import os
import multiprocessing
import sys
import logging
import warnings

import pytest
from django.utils.six.moves import map

# No logging
logging.disable(logging.CRITICAL)


if __name__ == '__main__':
args = sys.argv[1:]

verbosity = 1
if not args:
# If run with no args, try and run the testsuite as fast as possible.
# That means across all cores and with no high-falutin' plugins.

try:
cpu_count = int(multiprocessing.cpu_count())
except ValueError:
cpu_count = 1

args = [
'--capture=no', '--nomigrations', '-n=%d' % cpu_count,
'tests'
]
else:
# Some args/options specified. Check to see if any options have
# been specified. If they have, then don't set any
has_options = any(map(lambda x: x.startswith('--'), args))
if not has_options:
# Default options:
# --exitfirst Abort on first error/failure
# --capture=no Don't capture STDOUT
args.extend(['--capture=no', '--nomigrations', '--exitfirst'])
else:
args = [arg for arg in args if not arg.startswith('-')]

with warnings.catch_warnings():
# The warnings module in default configuration will never cause tests
# to fail, as it never raises an exception. We alter that behaviour by
# turning DeprecationWarnings into exceptions, but exclude warnings
# triggered by third-party libs. Note: The context manager is not
# thread safe. Behaviour with multiple threads is undefined.
warnings.filterwarnings('error', category=DeprecationWarning)
warnings.filterwarnings('error', category=RuntimeWarning)
libs = r'(sorl\.thumbnail.*|bs4.*|webtest.*|inspect.*|re.*)'
warnings.filterwarnings(
'ignore', r'.*', DeprecationWarning, libs)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
result_code = pytest.main(args)
sys.exit(result_code)
result_code = pytest.main()
sys.exit(result_code)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'pytest-cov==2.3.0',
'pytest-django==2.9.1',
'pytest-xdist==1.14',
'pytest-warnings==0.1.0',
'pytest==2.9.2',
'spec==0.11.1',
'tox==1.8.1',
Expand Down
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import os
import warnings

import django


def pytest_addoption(parser):
parser.addoption('--postgres', action='store_true')
parser.addoption(
'--deprecation', choices=['strict', 'log', 'none'], default='log')


def pytest_configure(config):
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')

deprecation = config.getoption('deprecation')
if deprecation == 'strict':
warnings.simplefilter('error', DeprecationWarning)
warnings.simplefilter('error', PendingDeprecationWarning)
warnings.simplefilter('error', RuntimeWarning)
if deprecation == 'log':
warnings.simplefilter('always', DeprecationWarning)
warnings.simplefilter('always', PendingDeprecationWarning)
warnings.simplefilter('always', RuntimeWarning)
elif deprecation == 'none':
# Deprecation warnings are ignored by default
pass

if config.getoption('postgres'):
os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2'
os.environ['DATABASE_NAME'] = 'oscar'
Expand Down

0 comments on commit db2a9d2

Please sign in to comment.