|
@@ -1,86 +1,8 @@
|
1
|
1
|
#!/usr/bin/env python
|
2
|
|
-"""
|
3
|
|
-Custom test runner
|
4
|
|
-
|
5
|
|
-If args or options, we run the testsuite as quickly as possible.
|
6
|
|
-
|
7
|
|
-If args but no options, we default to using the spec plugin and aborting on
|
8
|
|
-first error/failure.
|
9
|
|
-
|
10
|
|
-If options, we ignore defaults and pass options onto pytest.
|
11
|
|
-
|
12
|
|
-Examples:
|
13
|
|
-
|
14
|
|
-Run all tests (as fast as possible)
|
15
|
|
-$ ./runtests.py
|
16
|
|
-
|
17
|
|
-Run all unit tests (using spec output)
|
18
|
|
-$ ./runtests.py tests/unit
|
19
|
|
-
|
20
|
|
-Run all checkout unit tests (using spec output)
|
21
|
|
-$ ./runtests.py tests/unit/checkout
|
22
|
|
-
|
23
|
|
-Re-run failing tests (requires pytest-cache)
|
24
|
|
-$ ./runtests.py ... --lf
|
25
|
|
-
|
26
|
|
-Drop into pdb when a test fails
|
27
|
|
-$ ./runtests.py ... --pdb
|
28
|
|
-"""
|
29
|
|
-
|
30
|
|
-import os
|
31
|
|
-import multiprocessing
|
32
|
2
|
import sys
|
33
|
|
-import logging
|
34
|
|
-import warnings
|
35
|
3
|
|
36
|
4
|
import pytest
|
37
|
|
-from django.utils.six.moves import map
|
38
|
|
-
|
39
|
|
-# No logging
|
40
|
|
-logging.disable(logging.CRITICAL)
|
41
|
|
-
|
42
|
5
|
|
43
|
6
|
if __name__ == '__main__':
|
44
|
|
- args = sys.argv[1:]
|
45
|
|
-
|
46
|
|
- verbosity = 1
|
47
|
|
- if not args:
|
48
|
|
- # If run with no args, try and run the testsuite as fast as possible.
|
49
|
|
- # That means across all cores and with no high-falutin' plugins.
|
50
|
|
-
|
51
|
|
- try:
|
52
|
|
- cpu_count = int(multiprocessing.cpu_count())
|
53
|
|
- except ValueError:
|
54
|
|
- cpu_count = 1
|
55
|
|
-
|
56
|
|
- args = [
|
57
|
|
- '--capture=no', '--nomigrations', '-n=%d' % cpu_count,
|
58
|
|
- 'tests'
|
59
|
|
- ]
|
60
|
|
- else:
|
61
|
|
- # Some args/options specified. Check to see if any options have
|
62
|
|
- # been specified. If they have, then don't set any
|
63
|
|
- has_options = any(map(lambda x: x.startswith('--'), args))
|
64
|
|
- if not has_options:
|
65
|
|
- # Default options:
|
66
|
|
- # --exitfirst Abort on first error/failure
|
67
|
|
- # --capture=no Don't capture STDOUT
|
68
|
|
- args.extend(['--capture=no', '--nomigrations', '--exitfirst'])
|
69
|
|
- else:
|
70
|
|
- args = [arg for arg in args if not arg.startswith('-')]
|
71
|
|
-
|
72
|
|
- with warnings.catch_warnings():
|
73
|
|
- # The warnings module in default configuration will never cause tests
|
74
|
|
- # to fail, as it never raises an exception. We alter that behaviour by
|
75
|
|
- # turning DeprecationWarnings into exceptions, but exclude warnings
|
76
|
|
- # triggered by third-party libs. Note: The context manager is not
|
77
|
|
- # thread safe. Behaviour with multiple threads is undefined.
|
78
|
|
- warnings.filterwarnings('error', category=DeprecationWarning)
|
79
|
|
- warnings.filterwarnings('error', category=RuntimeWarning)
|
80
|
|
- libs = r'(sorl\.thumbnail.*|bs4.*|webtest.*|inspect.*|re.*)'
|
81
|
|
- warnings.filterwarnings(
|
82
|
|
- 'ignore', r'.*', DeprecationWarning, libs)
|
83
|
|
-
|
84
|
|
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
|
85
|
|
- result_code = pytest.main(args)
|
86
|
|
- sys.exit(result_code)
|
|
7
|
+ result_code = pytest.main()
|
|
8
|
+ sys.exit(result_code)
|