Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/test_cleanup' into hotfix/test…
Browse files Browse the repository at this point in the history
…_loop
  • Loading branch information
giulioungaretti committed Jul 26, 2016
2 parents 77ec6d3 + 6b216f2 commit 1bc76fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ install:
- python setup.py develop
# command to run tests
script:
- python qcodes/test.py -c
- python qcodes/test.py --skip-coverage
- python qcodes/test.py --mp-spawn
after_success:
# codecov
- cd qcodes
Expand Down
62 changes: 36 additions & 26 deletions qcodes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ def test_part(name):

if __name__ == '__main__':
import argparse
import coverage
import os
import multiprocessing as mp
import sys
mp.set_start_method('spawn')

try:
import coverage
coverage_missing = False
except ImportError:
coverage_missing = True

# make sure coverage looks for .coveragerc in the right place
os.chdir(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -70,39 +73,46 @@ def test_part(name):
description=('Core test suite for Qcodes, '
'covering everything except instrument drivers'))

parser.add_argument('-v', '--verbose', nargs='?', dest='verbosity',
const=2, default=1, type=int,
help=('increase verbosity. default 1, '
'-v is the same as -v 2'))
parser.add_argument('-v', '--verbose', action='store_true',
help='increase verbosity')

parser.add_argument('-q', '--quiet', action='store_true',
help='reduce verbosity (opposite of --verbose)')

parser.add_argument('-s', '--skip-coverage', action='store_true',
help='skip coverage reporting')

parser.add_argument('-c', '--coverage', nargs='?', dest='show_coverage',
const=1, default=1, type=int,
help=('show coverage. default is True '
'-c is the same as -c 1'))
parser.add_argument('-t', '--test_pattern', type=str, default='test*.py',
help=('regexp for test name to match, '
'default "test*.py"'))

parser.add_argument('-t', '--test_pattern', nargs='?', dest='test_pattern',
const=1, default='test*.py', type=str,
help=('regexp for test name to match'))
parser.add_argument('-f', '--failfast', action='store_true',
help='halt on first error/failure')

parser.add_argument('-f', '--failfast', nargs='?', dest='failfast',
const=1, default=0, type=int,
help=('halt on first error/failure? default 0 '
'(false), -f is the same as -f 1 (true)'))
parser.add_argument('-m', '--mp-spawn', action='store_true',
help=('force "spawn" method of starting child '
'processes to emulate Win behavior on Unix'))

args = parser.parse_args()

cov = coverage.Coverage()
cov.start()
if args.mp_spawn:
mp.set_start_method('spawn')

success = _test_core(verbosity=args.verbosity,
failfast=bool(args.failfast),
args.skip_coverage |= coverage_missing

if not args.skip_coverage:
cov = coverage.Coverage(source=['qcodes'])
cov.start()

success = _test_core(verbosity=(1 + args.verbose - args.quiet),
failfast=args.failfast,
test_pattern=args.test_pattern)

cov.stop()
# save coverage anyway since we computed it
cov.save()
if success and args.show_coverage:
if not args.skip_coverage:
cov.stop()
cov.save()
cov.report()

# restore unix-y behavior
# exit status 1 on fail
if not success:
Expand Down

0 comments on commit 1bc76fd

Please sign in to comment.