Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use pytest as testrunner instead of nose
  • Loading branch information
mvantellingen committed May 4, 2015
1 parent 76a46f7 commit 130ba4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
6 changes: 5 additions & 1 deletion requirements.txt
Expand Up @@ -23,10 +23,14 @@ sphinx_rtd_theme==0.1.6
# Testing
django-dynamic-fixture==1.8.1
coverage==3.7.1
django-nose==1.4
spec==0.11.1
WebTest==2.0.17
django-webtest==1.7.7
pytest==2.7.0
pytest-cache==1.0
pytest-cov==1.8.1
pytest-django==2.8.0
pytest-xdist==1.11
tox==1.8.1
coveralls==0.4.4
behave==1.2.4
Expand Down
46 changes: 19 additions & 27 deletions runtests.py
Expand Up @@ -20,60 +20,53 @@
Run all checkout unit tests (using spec output)
$ ./runtests.py tests/unit/checkout
Run all tests relating to shipping
$ ./runtests.py --attr=shipping
Re-run failing tests (needs to be run twice to first build the index)
$ ./runtests.py ... --failed
Re-run failing tests (requires pytest-cache)
$ ./runtests.py ... --lf
Drop into pdb when a test fails
$ ./runtests.py ... --pdb-failures
$ ./runtests.py ... --pdb
"""

import os
import multiprocessing
import sys
import logging
import warnings

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

# No logging
logging.disable(logging.CRITICAL)


def run_tests(verbosity, *test_args):
from django_nose import NoseTestSuiteRunner
test_runner = NoseTestSuiteRunner(verbosity=verbosity)
if not test_args:
test_args = ['tests']
num_failures = test_runner.run_tests(test_args)
if num_failures:
sys.exit(num_failures)


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.
args = ['--nocapture', '--stop', '--processes=-1', 'tests']

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 nose 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:
# --stop Abort on first error/failure
# --nocapture Don't capture STDOUT
args.extend(['--nocapture', '--stop'])
# --exitfirst Abort on first error/failure
# --capture=no Don't capture STDOUT
args.extend(['--capture=no', '--nomigrations', '--exitfirst'])
else:
# Remove options as nose will pick these up from sys.argv
for arg in args:
if arg.startswith('--verbosity'):
verbosity = int(arg[-1])
args = [arg for arg in args if not arg.startswith('-')]

with warnings.catch_warnings():
Expand All @@ -89,5 +82,4 @@ def run_tests(verbosity, *test_args):
'ignore', r'.*', DeprecationWarning, libs)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
django.setup()
run_tests(verbosity, *args)
pytest.main(args)
2 changes: 2 additions & 0 deletions setup.cfg
Expand Up @@ -3,3 +3,5 @@ universal=1

[pytest]
python_files=test_*.py *tests.py
addopts = --nomigrations
norecursedirs = .* *.egg sites src
5 changes: 0 additions & 5 deletions tests/settings.py
Expand Up @@ -87,9 +87,4 @@
OSCAR_INITIAL_LINE_STATUS = 'a'
OSCAR_LINE_STATUS_PIPELINE = {'a': ('b', ), 'b': ()}

# Setting this explicitly prevents Django 1.7+ from showing a
# warning regarding a changed default test runner. The Oscar test
# suite is run with nose, so it does not matter.
SILENCED_SYSTEM_CHECKS = ['1_6.W001']

SECRET_KEY = 'notverysecret'

0 comments on commit 130ba4c

Please sign in to comment.