Add TOX_PYDEV_DEBUG env variable to run_tests.py
Add new env variable to handle test cases execution when debugging test cases under a debugger by using testools.run runner. Change-Id: Ia6ec38e6471d93dd98c3fef17e66e9187c666c9d
This commit is contained in:
parent
e07c36d8f4
commit
3df2bb87f1
@ -22,6 +22,8 @@ import tempfile
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
BASH_EXECUTABLE = '/bin/bash'
|
||||
PYTHON_EXECUTABLE = os.environ.get('PYTHON', sys.executable)
|
||||
|
||||
|
||||
def get_logger(name):
|
||||
@ -52,6 +54,7 @@ def execute(command, *args, **kwargs):
|
||||
capture_stdout = kwargs.pop('capture_stdout', True)
|
||||
universal_newlines = kwargs.pop('universal_newlines', True)
|
||||
check = kwargs.pop('check', True)
|
||||
shell = kwargs.pop('shell', '/bin/bash')
|
||||
|
||||
if args or kwargs:
|
||||
command = command.format(*args, **kwargs)
|
||||
@ -59,7 +62,34 @@ def execute(command, *args, **kwargs):
|
||||
|
||||
stdout = capture_stdout and subprocess.PIPE or None
|
||||
|
||||
result = subprocess.run(['/bin/bash', '-x', '-c', command],
|
||||
if shell:
|
||||
command_line = [shell, '-x', '-c', command]
|
||||
else:
|
||||
command_line = shlex.split(command)
|
||||
|
||||
LOG.info(f"Execute: {command_line}")
|
||||
result = subprocess.run(command_line,
|
||||
stdout=stdout, shell=False,
|
||||
universal_newlines=universal_newlines)
|
||||
if check:
|
||||
result.check_returncode()
|
||||
return result.stdout
|
||||
|
||||
|
||||
def execute_python(command, *args, **kwargs):
|
||||
capture_stdout = kwargs.pop('capture_stdout', True)
|
||||
universal_newlines = kwargs.pop('universal_newlines', True)
|
||||
check = kwargs.pop('check', True)
|
||||
interpreter = kwargs.pop('interpreter', PYTHON_EXECUTABLE)
|
||||
|
||||
if args or kwargs:
|
||||
command = command.format(*args, **kwargs)
|
||||
command = command.strip()
|
||||
command_line = [interpreter] + shlex.split(command)
|
||||
|
||||
stdout = capture_stdout and subprocess.PIPE or None
|
||||
LOG.info(f"Execute: {command_line}")
|
||||
result = subprocess.run(command_line,
|
||||
stdout=stdout, shell=False,
|
||||
universal_newlines=universal_newlines)
|
||||
if check:
|
||||
|
@ -21,8 +21,6 @@ import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
|
||||
|
||||
TOP_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
if TOP_DIR not in sys.path:
|
||||
sys.path.insert(0, TOP_DIR)
|
||||
@ -53,6 +51,10 @@ TOX_REPORT_XML = os.environ.get(
|
||||
|
||||
TOX_RUN_TESTS_TIMEOUT = float(os.environ.get('TOX_RUN_TESTS_TIMEOUT') or 0.)
|
||||
|
||||
TOX_PYDEV_DEBUG = bool(
|
||||
os.environ.get('TOX_PYDEV_DEBUG', 'false').lower() in
|
||||
['true', 'yes', '1'])
|
||||
|
||||
|
||||
def main():
|
||||
common.setup_logging()
|
||||
@ -75,6 +77,10 @@ def run_tests():
|
||||
cleanup_report_dir()
|
||||
log_environ()
|
||||
|
||||
if TOX_PYDEV_DEBUG:
|
||||
debug_test_cases()
|
||||
return True
|
||||
|
||||
succeeded = True
|
||||
try:
|
||||
run_test_cases()
|
||||
@ -149,6 +155,12 @@ def log_tests_results():
|
||||
check=False)
|
||||
|
||||
|
||||
def debug_test_cases():
|
||||
common.execute_python('-m testtools.run {posargs}',
|
||||
posargs=common.get_posargs(),
|
||||
capture_stdout=False)
|
||||
|
||||
|
||||
def run_test_cases():
|
||||
common.execute('stestr run --slowest {posargs}',
|
||||
posargs=common.get_posargs(),
|
||||
|
Loading…
Reference in New Issue
Block a user