浏览代码

Use pytest as testrunner instead of nose

master
Michael van Tellingen 10 年前
父节点
当前提交
130ba4c0bf
共有 4 个文件被更改,包括 26 次插入33 次删除
  1. 5
    1
      requirements.txt
  2. 19
    27
      runtests.py
  3. 2
    0
      setup.cfg
  4. 0
    5
      tests/settings.py

+ 5
- 1
requirements.txt 查看文件

23
 # Testing
23
 # Testing
24
 django-dynamic-fixture==1.8.1
24
 django-dynamic-fixture==1.8.1
25
 coverage==3.7.1
25
 coverage==3.7.1
26
-django-nose==1.4
27
 spec==0.11.1
26
 spec==0.11.1
28
 WebTest==2.0.17
27
 WebTest==2.0.17
29
 django-webtest==1.7.7
28
 django-webtest==1.7.7
29
+pytest==2.7.0
30
+pytest-cache==1.0
31
+pytest-cov==1.8.1
32
+pytest-django==2.8.0
33
+pytest-xdist==1.11
30
 tox==1.8.1
34
 tox==1.8.1
31
 coveralls==0.4.4
35
 coveralls==0.4.4
32
 behave==1.2.4
36
 behave==1.2.4

+ 19
- 27
runtests.py 查看文件

20
 Run all checkout unit tests (using spec output)
20
 Run all checkout unit tests (using spec output)
21
 $ ./runtests.py tests/unit/checkout
21
 $ ./runtests.py tests/unit/checkout
22
 
22
 
23
-Run all tests relating to shipping
24
-$ ./runtests.py --attr=shipping
25
-
26
-Re-run failing tests (needs to be run twice to first build the index)
27
-$ ./runtests.py ... --failed
23
+Re-run failing tests (requires pytest-cache)
24
+$ ./runtests.py ... --lf
28
 
25
 
29
 Drop into pdb when a test fails
26
 Drop into pdb when a test fails
30
-$ ./runtests.py ... --pdb-failures
27
+$ ./runtests.py ... --pdb
31
 """
28
 """
32
 
29
 
33
 import os
30
 import os
31
+import multiprocessing
34
 import sys
32
 import sys
35
 import logging
33
 import logging
36
 import warnings
34
 import warnings
37
 
35
 
38
-import django
36
+import pytest
39
 from django.utils.six.moves import map
37
 from django.utils.six.moves import map
40
 
38
 
41
 # No logging
39
 # No logging
42
 logging.disable(logging.CRITICAL)
40
 logging.disable(logging.CRITICAL)
43
 
41
 
44
 
42
 
45
-def run_tests(verbosity, *test_args):
46
-    from django_nose import NoseTestSuiteRunner
47
-    test_runner = NoseTestSuiteRunner(verbosity=verbosity)
48
-    if not test_args:
49
-        test_args = ['tests']
50
-    num_failures = test_runner.run_tests(test_args)
51
-    if num_failures:
52
-        sys.exit(num_failures)
53
-
54
-
55
 if __name__ == '__main__':
43
 if __name__ == '__main__':
56
     args = sys.argv[1:]
44
     args = sys.argv[1:]
57
 
45
 
59
     if not args:
47
     if not args:
60
         # If run with no args, try and run the testsuite as fast as possible.
48
         # If run with no args, try and run the testsuite as fast as possible.
61
         # That means across all cores and with no high-falutin' plugins.
49
         # That means across all cores and with no high-falutin' plugins.
62
-        args = ['--nocapture', '--stop', '--processes=-1', 'tests']
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
+        ]
63
     else:
60
     else:
64
         # Some args/options specified.  Check to see if any nose options have
61
         # Some args/options specified.  Check to see if any nose options have
65
         # been specified.  If they have, then don't set any
62
         # been specified.  If they have, then don't set any
66
         has_options = any(map(lambda x: x.startswith('--'), args))
63
         has_options = any(map(lambda x: x.startswith('--'), args))
67
         if not has_options:
64
         if not has_options:
68
             # Default options:
65
             # Default options:
69
-            # --stop Abort on first error/failure
70
-            # --nocapture Don't capture STDOUT
71
-            args.extend(['--nocapture', '--stop'])
66
+            # --exitfirst Abort on first error/failure
67
+            # --capture=no Don't capture STDOUT
68
+            args.extend(['--capture=no', '--nomigrations', '--exitfirst'])
72
         else:
69
         else:
73
-            # Remove options as nose will pick these up from sys.argv
74
-            for arg in args:
75
-                if arg.startswith('--verbosity'):
76
-                    verbosity = int(arg[-1])
77
             args = [arg for arg in args if not arg.startswith('-')]
70
             args = [arg for arg in args if not arg.startswith('-')]
78
 
71
 
79
     with warnings.catch_warnings():
72
     with warnings.catch_warnings():
89
             'ignore', r'.*', DeprecationWarning, libs)
82
             'ignore', r'.*', DeprecationWarning, libs)
90
 
83
 
91
         os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
84
         os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
92
-        django.setup()
93
-        run_tests(verbosity, *args)
85
+        pytest.main(args)

+ 2
- 0
setup.cfg 查看文件

3
 
3
 
4
 [pytest]
4
 [pytest]
5
 python_files=test_*.py *tests.py
5
 python_files=test_*.py *tests.py
6
+addopts = --nomigrations
7
+norecursedirs = .* *.egg sites src

+ 0
- 5
tests/settings.py 查看文件

87
 OSCAR_INITIAL_LINE_STATUS = 'a'
87
 OSCAR_INITIAL_LINE_STATUS = 'a'
88
 OSCAR_LINE_STATUS_PIPELINE = {'a': ('b', ), 'b': ()}
88
 OSCAR_LINE_STATUS_PIPELINE = {'a': ('b', ), 'b': ()}
89
 
89
 
90
-# Setting this explicitly prevents Django 1.7+ from showing a
91
-# warning regarding a changed default test runner. The Oscar test
92
-# suite is run with nose, so it does not matter.
93
-SILENCED_SYSTEM_CHECKS = ['1_6.W001']
94
-
95
 SECRET_KEY = 'notverysecret'
90
 SECRET_KEY = 'notverysecret'

正在加载...
取消
保存