Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collects failed assets on LyTestTools test failures #7368

Merged
merged 10 commits into from
Feb 10, 2022
Prev Previous commit
Next Next commit
Changed query to all lines because of current asset logging bug
Signed-off-by: evanchia <evanchia@amazon.com>
  • Loading branch information
evanchia-ly-sdets committed Feb 3, 2022
commit 61e96d5fa37a71ce6091635ba9095c6e0ef8788d
21 changes: 10 additions & 11 deletions Tools/LyTestTools/ly_test_tools/o3de/editor_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,22 @@ def save_failed_asset_joblogs(workspace: AbstractWorkspace) -> None:

def _check_log_errors_warnings(log_path: str) -> bool:
"""
Checks to see if the asset log contains any errors or warnings by reading the last line of the file.
Example log line: '~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 0 errors, 1 warnings'
Checks to see if the asset log contains any errors or warnings by reading the last line of the file. There are
multiple types of log regex. Returns True is no regex is found because something probably went wrong.
Example log lines: ~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 0 errors, 1 warnings
(Current issue where the expected line isn't always the last line. This function will instead query each line until
the issue is resolved).
evanchia-ly-sdets marked this conversation as resolved.
Show resolved Hide resolved

:param log_path: The pull path to the asset log file to read
evanchia-ly-sdets marked this conversation as resolved.
Show resolved Hide resolved
:return: True if the last line regex finds an error or warning, else False
"""
log_regex = "(\\d+) errors, (\\d+) warnings"
with open(log_path, 'r') as opened_asset_log:
# Read the last line
for log_line in opened_asset_log:
pass
last_line = log_line
# Use regex to see if there are any non zero values for errors or warnings
regex_match = re.search(log_regex, last_line)
if regex_match is None:
logger.warning(f"Regex for asset log is expected to be in the form:\nn errors, n warnings\nActual: {last_line}")
return False
if (int)(regex_match.group(1)) != 0 or (int)(regex_match.group(2)) != 0:
regex_match = re.search(log_regex, log_line)
if regex_match is not None:
break
# If we match any non zero numbers in: n error, n warnings
if regex_match is None or (int)(regex_match.group(1)) != 0 or (int)(regex_match.group(2)) != 0:
return True
return False
8 changes: 4 additions & 4 deletions Tools/LyTestTools/tests/unit/test_editor_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,25 @@ def test_CheckLogErrorWarnings_ValidLine_ReturnsTrue(self):
assert expected

def test_CheckLogErrorWarnings_MultipleValidLine_ReturnsTrue(self):
mock_log = '~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 1 errors, 1 warnings'
mock_log = 'foo\nfoo\n~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 1 errors, 1 warnings'
mock_log_path = mock.MagicMock()

with mock.patch('builtins.open', mock.mock_open(read_data=mock_log)) as mock_file:
expected = editor_test_utils._check_log_errors_warnings(mock_log_path)
assert expected

def test_CheckLogErrorWarnings_InvalidLine_ReturnsFalse(self):
mock_log = '~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 0 errors, 0 warnings'
mock_log = 'foo\n~~1643759303647~~1~~00000000000009E0~~AssetBuilder~~S: 0 errors, 0 warnings'
mock_log_path = mock.MagicMock()

with mock.patch('builtins.open', mock.mock_open(read_data=mock_log)) as mock_file:
expected = editor_test_utils._check_log_errors_warnings(mock_log_path)
assert not expected

def test_CheckLogErrorWarnings_InvalidRegex_ReturnsFalse(self):
def test_CheckLogErrorWarnings_InvalidRegex_ReturnsTrue(self):
mock_log = 'Invalid last line'
mock_log_path = mock.MagicMock()

with mock.patch('builtins.open', mock.mock_open(read_data=mock_log)) as mock_file:
expected = editor_test_utils._check_log_errors_warnings(mock_log_path)
assert not expected
assert expected