better logic in running system tests, thanks Paolo

This commit is contained in:
mdipierro
2019-03-30 10:42:01 -07:00
parent 44b93929e2
commit cfdee6e065
2 changed files with 26 additions and 21 deletions
+25 -20
View File
@@ -54,33 +54,38 @@ def run_system_tests(options):
""" """
Runs unittests for gluon.tests Runs unittests for gluon.tests
""" """
import subprocess # see "python -m unittest -h" for unittest options help
major_version = sys.version_info[0] # NOTE: someone might be interested either in using the
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests'] # -f (--failfast) option to stop testing on first failure, or
if major_version == 2: # in customizing the test selection, for example to run only
sys.stderr.write("Python 2.7\n") # 'gluon.tests.<module>', 'gluon.tests.<module>.<class>' (this
else: # could be shortened as 'gluon.tests.<class>'), or even
sys.stderr.write("Experimental Python 3.x.\n") # 'gluon.tests.<module>.<class>.<method>' (or
# the shorter 'gluon.tests.<class>.<method>')
call_args = ['-m', 'unittest', '-c', 'gluon.tests']
if options.verbose:
call_args.insert(-1, '-v')
if options.with_coverage: if options.with_coverage:
has_coverage = False
coverage_exec = 'coverage2' if major_version == 2 else 'coverage3'
try: try:
import coverage import coverage
has_coverage = True
except: except:
sys.stderr.write('Coverage was not installed, skipping\n') sys.stderr.write('Coverage was not installed\n')
sys.exit(256)
if not PY2:
sys.stderr.write('Experimental ')
sys.stderr.write("Python %s\n" % sys.version)
if options.with_coverage:
coverage_exec = 'coverage2' if PY2 else 'coverage3'
coverage_config_file = os.path.join('gluon', 'tests', 'coverage.ini') coverage_config_file = os.path.join('gluon', 'tests', 'coverage.ini')
coverage_config = os.environ.setdefault("COVERAGE_PROCESS_START", coverage_config = os.environ.setdefault("COVERAGE_PROCESS_START",
coverage_config_file) coverage_config_file)
call_args = [coverage_exec, 'run', '--rcfile=%s' % run_args = [coverage_exec, 'run', '--rcfile=%s' % coverage_config]
coverage_config, '-m', 'unittest', '-v', 'gluon.tests'] # replace the current process
if has_coverage: os.execvpe(run_args[0], run_args + call_args, os.environ)
ret = subprocess.call(call_args)
else:
ret = 256
else: else:
ret = subprocess.call(call_args) run_args = [sys.executable]
sys.exit(ret and 1) # replace the current process
os.execv(run_args[0], run_args + call_args)
class IO(object): class IO(object):
@@ -1012,7 +1017,7 @@ def console():
options.interfaces.append(tuple(interface)) options.interfaces.append(tuple(interface))
# accepts --scheduler in the form # accepts --scheduler in the form
# "app:group1,group2,app2:group1" # "app:group1:group2,app2:group1"
scheduler = [] scheduler = []
options.scheduler_groups = None options.scheduler_groups = None
if isinstance(options.scheduler, str): if isinstance(options.scheduler, str):