From c8fd8f74928716d56756028e41dfa9c5625ac742 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:21:32 +0200 Subject: [PATCH 1/6] cleanup argparse usage --- qcodes/test.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/qcodes/test.py b/qcodes/test.py index 3b02cf5949a..b439636e352 100644 --- a/qcodes/test.py +++ b/qcodes/test.py @@ -70,39 +70,39 @@ 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('-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('-q', '--quiet', action='store_true', + help='reduce verbosity (opposite of --verbose)') - 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('-s', '--skip-coverage', action='store_true', + help='skip coverage reporting') - 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('-t', '--test_pattern', type=str, default='test*.py', + help=('regexp for test name to match, ' + 'default "test*.py"')) + + parser.add_argument('-f', '--failfast', action='store_true', + help='halt on first error/failure') args = parser.parse_args() - cov = coverage.Coverage(source=['qcodes']) - cov.start() + if not args.skip_coverage: + cov = coverage.Coverage(source=['qcodes']) + cov.start() - success = _test_core(verbosity=args.verbosity, - failfast=bool(args.failfast), + 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: - cov.report() + if not args.skip_coverage: + cov.stop() + # save coverage anyway since we computed it + cov.save() + if success and args.skip_coverage: + cov.report() + # restore unix-y behavior # exit status 1 on fail if not success: From 9011f088fa8b9432e0c73d2dceba794c12d7384d Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:22:11 +0200 Subject: [PATCH 2/6] remove duplicate import --- qcodes/test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qcodes/test.py b/qcodes/test.py index b439636e352..2f9e5b41ae2 100644 --- a/qcodes/test.py +++ b/qcodes/test.py @@ -60,7 +60,6 @@ def test_part(name): import coverage import os import multiprocessing as mp - import sys mp.set_start_method('spawn') # make sure coverage looks for .coveragerc in the right place From 2a59a66b91dc78f83e7ea0f10a9bf990f93313b1 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:25:18 +0200 Subject: [PATCH 3/6] only use coverage if available (it is an extra) --- qcodes/test.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qcodes/test.py b/qcodes/test.py index 2f9e5b41ae2..947904a8e28 100644 --- a/qcodes/test.py +++ b/qcodes/test.py @@ -57,9 +57,15 @@ def test_part(name): if __name__ == '__main__': import argparse - import coverage import os import multiprocessing as mp + + try: + import coverage + coverage_available = True + except ImportError: + coverage_available = False + mp.set_start_method('spawn') # make sure coverage looks for .coveragerc in the right place @@ -87,6 +93,8 @@ def test_part(name): args = parser.parse_args() + args.skip_coverage &= coverage_available + if not args.skip_coverage: cov = coverage.Coverage(source=['qcodes']) cov.start() From ed56ef75cb442a79897bc4484929bb84aa12bab3 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:32:07 +0200 Subject: [PATCH 4/6] make child start method controllable --- qcodes/test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qcodes/test.py b/qcodes/test.py index 947904a8e28..748147c4fac 100644 --- a/qcodes/test.py +++ b/qcodes/test.py @@ -66,8 +66,6 @@ def test_part(name): except ImportError: coverage_available = False - mp.set_start_method('spawn') - # make sure coverage looks for .coveragerc in the right place os.chdir(os.path.dirname(os.path.abspath(__file__))) @@ -91,8 +89,15 @@ def test_part(name): parser.add_argument('-f', '--failfast', action='store_true', help='halt on first error/failure') + 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() + if args.mp_spawn: + mp.set_start_method('spawn') + args.skip_coverage &= coverage_available if not args.skip_coverage: From 78715df6315dd67fce6016115d587aa63e51bd6a Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:32:53 +0200 Subject: [PATCH 5/6] update travis config, test both child spawn methods --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6002718484e..f3036ea8829 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From 6b216f25ec41503e5fe2e837d9a4b146586e1df4 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 26 Jul 2016 00:37:46 +0200 Subject: [PATCH 6/6] fix logic of skipping coverage --- qcodes/test.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/qcodes/test.py b/qcodes/test.py index 748147c4fac..b04c412b06a 100644 --- a/qcodes/test.py +++ b/qcodes/test.py @@ -62,9 +62,9 @@ def test_part(name): try: import coverage - coverage_available = True + coverage_missing = False except ImportError: - coverage_available = False + coverage_missing = True # make sure coverage looks for .coveragerc in the right place os.chdir(os.path.dirname(os.path.abspath(__file__))) @@ -98,7 +98,7 @@ def test_part(name): if args.mp_spawn: mp.set_start_method('spawn') - args.skip_coverage &= coverage_available + args.skip_coverage |= coverage_missing if not args.skip_coverage: cov = coverage.Coverage(source=['qcodes']) @@ -110,10 +110,8 @@ def test_part(name): if not args.skip_coverage: cov.stop() - # save coverage anyway since we computed it cov.save() - if success and args.skip_coverage: - cov.report() + cov.report() # restore unix-y behavior # exit status 1 on fail