瀏覽代碼

Alter the runtests.py script to just call py.test (keep it simple)

travis: Run py.test --cov=oscar instead of coverage run
master
Michael van Tellingen 8 年之前
父節點
當前提交
db2a9d255e
沒有連結到貢獻者的電子郵件帳戶。
共有 4 個檔案被更改,包括 21 行新增82 行删除
  1. 1
    2
      Makefile
  2. 2
    80
      runtests.py
  3. 1
    0
      setup.py
  4. 17
    0
      tests/conftest.py

+ 1
- 2
Makefile 查看文件

@@ -31,8 +31,7 @@ docs:
31 31
 	cd docs && make html
32 32
 
33 33
 coverage:
34
-	coverage run ./runtests.py --with-xunit
35
-	coverage xml -i
34
+	py.test --cov=oscar --cov-report=term-missing
36 35
 
37 36
 lint:
38 37
 	./lint.sh

+ 2
- 80
runtests.py 查看文件

@@ -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)

+ 1
- 0
setup.py 查看文件

@@ -64,6 +64,7 @@ test_requires = [
64 64
     'pytest-cov==2.3.0',
65 65
     'pytest-django==2.9.1',
66 66
     'pytest-xdist==1.14',
67
+    'pytest-warnings==0.1.0',
67 68
     'pytest==2.9.2',
68 69
     'spec==0.11.1',
69 70
     'tox==1.8.1',

+ 17
- 0
tests/conftest.py 查看文件

@@ -1,14 +1,31 @@
1 1
 import os
2
+import warnings
3
+
2 4
 import django
3 5
 
4 6
 
5 7
 def pytest_addoption(parser):
6 8
     parser.addoption('--postgres', action='store_true')
9
+    parser.addoption(
10
+        '--deprecation', choices=['strict', 'log', 'none'], default='log')
7 11
 
8 12
 
9 13
 def pytest_configure(config):
10 14
     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
11 15
 
16
+    deprecation = config.getoption('deprecation')
17
+    if deprecation == 'strict':
18
+        warnings.simplefilter('error', DeprecationWarning)
19
+        warnings.simplefilter('error', PendingDeprecationWarning)
20
+        warnings.simplefilter('error', RuntimeWarning)
21
+    if deprecation == 'log':
22
+        warnings.simplefilter('always', DeprecationWarning)
23
+        warnings.simplefilter('always', PendingDeprecationWarning)
24
+        warnings.simplefilter('always', RuntimeWarning)
25
+    elif deprecation == 'none':
26
+        # Deprecation warnings are ignored by default
27
+        pass
28
+
12 29
     if config.getoption('postgres'):
13 30
         os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2'
14 31
         os.environ['DATABASE_NAME'] = 'oscar'

Loading…
取消
儲存