Integrating latest 47acbe8
This commit is contained in:
+13
-7
@@ -14,14 +14,19 @@ import sys
|
||||
from ly_test_tools import WINDOWS
|
||||
|
||||
|
||||
def _get_test_launcher_cmd():
|
||||
def _get_test_launcher_cmd(build_dir=None):
|
||||
"""
|
||||
Helper function to determine the test launcher command for the current platform
|
||||
:param build_dir: the --build-directory arg that is passed to determine which build dir to use. Can also be None
|
||||
:return: The test launcher command
|
||||
"""
|
||||
python_runner = "python3.cmd"
|
||||
build_arg = ""
|
||||
if build_dir:
|
||||
build_arg = f"--build-directory {build_dir} "
|
||||
|
||||
python_runner = "python.cmd"
|
||||
if not WINDOWS:
|
||||
python_runner = "python3.sh"
|
||||
python_runner = "python.sh"
|
||||
current_dir = sys.executable
|
||||
|
||||
# Look upward a handful of levels to check for the LY python entry point script
|
||||
@@ -29,12 +34,12 @@ def _get_test_launcher_cmd():
|
||||
for _ in range(10):
|
||||
python_wrapper = os.path.join(current_dir, python_runner)
|
||||
if os.path.exists(python_wrapper):
|
||||
return f"{python_wrapper} -m pytest "
|
||||
return f"{python_wrapper} -m pytest{build_arg} "
|
||||
# Using an explicit else to avoid aberrant behavior from following filesystem links
|
||||
else:
|
||||
current_dir = os.path.abspath(os.path.join(current_dir, os.path.pardir))
|
||||
|
||||
return f"{sys.executable} -m pytest "
|
||||
return f"{sys.executable} -m pytest{build_arg} "
|
||||
|
||||
|
||||
def _format_cmd(launcher_cmd, test_path, nodeid):
|
||||
@@ -65,17 +70,18 @@ def _format_cmd(launcher_cmd, test_path, nodeid):
|
||||
return f"{launcher_cmd}{test_id_argument}"
|
||||
|
||||
|
||||
def build_rerun_commands(test_path, nodeids):
|
||||
def build_rerun_commands(test_path, nodeids, build_dir=None):
|
||||
"""
|
||||
Builds a list of commands to run tests
|
||||
|
||||
:param test_path: File or directory that contains the test(s) that were run
|
||||
:param nodeids: List of test node ids, with parametrized values
|
||||
:param build_dir: the --build-directory arg that is passed to determine which build dir to use. Can also be None
|
||||
:return: A list of commands to re-run tests
|
||||
"""
|
||||
|
||||
commands = []
|
||||
test_launcher_cmd = _get_test_launcher_cmd()
|
||||
test_launcher_cmd = _get_test_launcher_cmd(build_dir)
|
||||
|
||||
for nodeid in nodeids:
|
||||
commands.append(_format_cmd(test_launcher_cmd, test_path, nodeid))
|
||||
|
||||
@@ -13,32 +13,39 @@ import os
|
||||
import ly_test_tools._internal.pytest_plugin.failed_test_rerun_command as rerun
|
||||
|
||||
|
||||
def _add_commands(terminalreporter, header, test_path, nodeids):
|
||||
def _add_commands(terminalreporter, header, test_path, nodeids, build_dir=None):
|
||||
"""
|
||||
Add test re-run commands to the TerminalReporter object
|
||||
:param terminalreporter: Pytest's TerminalReporter object that contains test result information.
|
||||
:param header: Message to write to TerminalReporter before list is added
|
||||
:param test_path: File or directory that contains the test(s) that to run
|
||||
:param nodeids: List of test node ids, with parametrized values
|
||||
:param build_dir: the --build-directory arg that is passed to determine which build dir to use. Can also be None
|
||||
"""
|
||||
|
||||
terminalreporter.write_line(header)
|
||||
|
||||
if nodeids:
|
||||
commands = rerun.build_rerun_commands(test_path, nodeids)
|
||||
commands = rerun.build_rerun_commands(test_path, nodeids, build_dir)
|
||||
for command in commands:
|
||||
terminalreporter.write_line(command)
|
||||
else:
|
||||
terminalreporter.write_line("Error, Test node id list is empty!")
|
||||
|
||||
|
||||
def pytest_terminal_summary(terminalreporter, exitstatus):
|
||||
def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
||||
"""
|
||||
Pytest's hook for terminal reporting. This hook is invoked at the end of the test session.
|
||||
|
||||
:param terminalreporter: Pytest's TerminalReporter object that contains test result information.
|
||||
:param exitstatus: Exit that will be returned to the system
|
||||
"""
|
||||
# Check to see if the build directory was passed
|
||||
build_dir = None
|
||||
try:
|
||||
build_dir = config.known_args_namespace.build_directory
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Add to the TerminalReport a section for failed test re-running
|
||||
failures = terminalreporter.stats.get('failed', [])
|
||||
@@ -62,7 +69,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
|
||||
terminalreporter,
|
||||
"Use the following commands to re-run each test that failed locally\n"
|
||||
"(NOTE: The 'PYTHON' or 'PYTHONPATH' environment variables need values for accurate commands): ",
|
||||
test_path, nodeids)
|
||||
test_path, nodeids, build_dir)
|
||||
|
||||
if error_count:
|
||||
nodeids = [os.path.basename(report.nodeid) for report in errors]
|
||||
@@ -71,4 +78,4 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
|
||||
terminalreporter,
|
||||
"Use the following commands to re-run each test that had errors locally\n"
|
||||
"(NOTE: The 'PYTHON' or 'PYTHONPATH' environment variables need values for accurate commands): ",
|
||||
test_path, nodeids)
|
||||
test_path, nodeids, build_dir)
|
||||
|
||||
@@ -126,6 +126,7 @@ def kill_processes_with_name_not_started_from(name, path):
|
||||
else:
|
||||
logger.warning(f"Path:'{path}' not found")
|
||||
|
||||
|
||||
def kill_process_with_pid(pid, raise_on_missing=False):
|
||||
"""
|
||||
Kills the process with the specified pid
|
||||
@@ -367,7 +368,10 @@ def _safe_kill_process_list(proc_list):
|
||||
except Exception: # purposefully broad
|
||||
logger.warning("Unexpected exception while terminating process", exc_info=True)
|
||||
|
||||
psutil.wait_procs(proc_list, timeout=30, callback=on_terminate)
|
||||
try:
|
||||
psutil.wait_procs(proc_list, timeout=30, callback=on_terminate)
|
||||
except Exception: # purposefully broad
|
||||
logger.warning("Unexpected exception while waiting for process to terminate", exc_info=True)
|
||||
|
||||
|
||||
def _terminate_and_confirm_dead(proc):
|
||||
|
||||
@@ -220,7 +220,7 @@ def platform_enabled(workspace: pytest.fixture, platform: str) -> bool:
|
||||
Checks to see if the platform specified is enabled for the current build of LY.
|
||||
|
||||
:param workspace: The current testing workspace
|
||||
:param platform: The name of the platform to lookup. Example Platforms: 'Xenia', 'Provo', 'Salem'
|
||||
:param platform: The name of the platform to lookup.
|
||||
:return: True if the platform is enabled, False if not.
|
||||
"""
|
||||
user_settings_file = os.path.join(workspace.paths.dev(), "_WAF_", "user_settings.options")
|
||||
|
||||
Reference in New Issue
Block a user