~ubuntu-qa-website-devel/ubuntu-qa-website/drupal7-rewrite

« back to all changes in this revision

Viewing changes to python-library/tests/run

  • Committer: nskaggs
  • Date: 2016-03-01 21:34:00 UTC
  • mfrom: (426.1.1 ubuntu-qa-website)
  • Revision ID: nicholas.skaggs@canonical.com-20160301213400-msn178a30monztmp
add Stephane's original python API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
import unittest
 
3
import os
 
4
import re
 
5
import shutil
 
6
import sys
 
7
 
 
8
coverage = True
 
9
try:
 
10
    from coverage import coverage
 
11
    cov = coverage()
 
12
    cov.start()
 
13
except ImportError:
 
14
    print("No coverage report, make sure python-coverage is installed")
 
15
    coverage = False
 
16
 
 
17
sys.path.insert(0, '.')
 
18
 
 
19
if len(sys.argv) > 1:
 
20
    test_filter = sys.argv[1]
 
21
else:
 
22
    test_filter = ''
 
23
 
 
24
tests = [t[:-3] for t in os.listdir('tests')
 
25
         if t.startswith('test_') and t.endswith('.py') and
 
26
         re.search(test_filter, t)]
 
27
tests.sort()
 
28
suite = unittest.TestLoader().loadTestsFromNames(tests)
 
29
res = unittest.TextTestRunner(verbosity=2).run(suite)
 
30
 
 
31
if coverage:
 
32
    if os.path.exists('tests/coverage'):
 
33
        shutil.rmtree('tests/coverage')
 
34
    cov.stop()
 
35
    cov.html_report(include=["qatracker.py"], directory='tests/coverage')