Bläddra i källkod

Use pytest as testrunner instead of nose

master
Michael van Tellingen 10 år sedan
förälder
incheckning
130ba4c0bf
4 ändrade filer med 26 tillägg och 33 borttagningar
  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 Visa fil

@@ -23,10 +23,14 @@ sphinx_rtd_theme==0.1.6
23 23
 # Testing
24 24
 django-dynamic-fixture==1.8.1
25 25
 coverage==3.7.1
26
-django-nose==1.4
27 26
 spec==0.11.1
28 27
 WebTest==2.0.17
29 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 34
 tox==1.8.1
31 35
 coveralls==0.4.4
32 36
 behave==1.2.4

+ 19
- 27
runtests.py Visa fil

@@ -20,38 +20,26 @@ $ ./runtests.py tests/unit
20 20
 Run all checkout unit tests (using spec output)
21 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 26
 Drop into pdb when a test fails
30
-$ ./runtests.py ... --pdb-failures
27
+$ ./runtests.py ... --pdb
31 28
 """
32 29
 
33 30
 import os
31
+import multiprocessing
34 32
 import sys
35 33
 import logging
36 34
 import warnings
37 35
 
38
-import django
36
+import pytest
39 37
 from django.utils.six.moves import map
40 38
 
41 39
 # No logging
42 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 43
 if __name__ == '__main__':
56 44
     args = sys.argv[1:]
57 45
 
@@ -59,21 +47,26 @@ if __name__ == '__main__':
59 47
     if not args:
60 48
         # If run with no args, try and run the testsuite as fast as possible.
61 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 60
     else:
64 61
         # Some args/options specified.  Check to see if any nose options have
65 62
         # been specified.  If they have, then don't set any
66 63
         has_options = any(map(lambda x: x.startswith('--'), args))
67 64
         if not has_options:
68 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 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 70
             args = [arg for arg in args if not arg.startswith('-')]
78 71
 
79 72
     with warnings.catch_warnings():
@@ -89,5 +82,4 @@ if __name__ == '__main__':
89 82
             'ignore', r'.*', DeprecationWarning, libs)
90 83
 
91 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 Visa fil

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

+ 0
- 5
tests/settings.py Visa fil

@@ -87,9 +87,4 @@ OSCAR_ORDER_STATUS_PIPELINE = {'A': ('B',), 'B': ()}
87 87
 OSCAR_INITIAL_LINE_STATUS = 'a'
88 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 90
 SECRET_KEY = 'notverysecret'

Laddar…
Avbryt
Spara