Przeglądaj źródła

Extended test runner to generate coverage stats

master
David Winterbottom 13 lat temu
rodzic
commit
2089b12408
4 zmienionych plików z 22 dodań i 5 usunięć
  1. 2
    0
      .gitignore
  2. 18
    3
      run_tests.py
  3. 1
    1
      sandbox/templates/layout.html
  4. 1
    1
      tests/templates/layout.html

+ 2
- 0
.gitignore Wyświetl plik

@@ -28,3 +28,5 @@ sandbox/*.sqlite
28 28
 sandbox/assets/*
29 29
 .idea
30 30
 TODO
31
+.coverage
32
+htmlcov/*

+ 18
- 3
run_tests.py Wyświetl plik

@@ -3,6 +3,7 @@ import sys
3 3
 import os
4 4
 import logging
5 5
 from optparse import OptionParser
6
+from coverage import coverage
6 7
 
7 8
 import tests.config
8 9
 
@@ -15,10 +16,24 @@ def run_tests(*test_args):
15 16
     test_runner = DjangoTestSuiteRunner(verbosity=1)
16 17
     if not test_args:
17 18
         test_args = ['oscar']
18
-    failures = test_runner.run_tests(test_args)
19
-    sys.exit(failures)
19
+    num_failures = test_runner.run_tests(test_args)
20
+    if num_failures:
21
+        sys.exit(num_failures)
20 22
 
21 23
 if __name__ == '__main__':
22 24
     parser = OptionParser()
25
+    parser.add_option('-c', '--coverage', dest='use_coverage', default=False,
26
+                      action='store_true', help="Generate coverage report")
23 27
     (options, args) = parser.parse_args()
24
-    run_tests(*args)
28
+
29
+    if options.use_coverage:
30
+        print 'Running tests with coverage'
31
+        c = coverage(source=['oscar'])
32
+        c.start()
33
+        run_tests(*args)
34
+        c.stop()
35
+        print 'Generate HTML reports'
36
+        c.html_report()
37
+    else:
38
+        print 'Running tests'
39
+        run_tests(*args)

+ 1
- 1
sandbox/templates/layout.html Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 {% extends "base.html" %}
2 2
 
3 3
 {% load currency_filters %}
4
-{% load promotions %}
4
+{% load promotion_tags %}
5 5
 {% load category_tags %}
6 6
 
7 7
 {% block layout %}

+ 1
- 1
tests/templates/layout.html Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 {% extends "base.html" %}
2 2
 
3 3
 {% load currency_filters %}
4
-{% load promotions %}
4
+{% load promotion_tags %}
5 5
 {% load category_tags %}
6 6
 
7 7
 {% block layout %}

Ładowanie…
Anuluj
Zapisz