-
Notifications
You must be signed in to change notification settings - Fork 26
fix: surface subprocess errors when pytest XML is missing #2141
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
Merged
+16
−18
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
|
|
||
| import os | ||
| import re | ||
| from typing import TYPE_CHECKING | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from junitparser.xunit2 import JUnitXml | ||
|
|
||
|
|
@@ -48,7 +48,7 @@ | |
| ) | ||
|
|
||
|
|
||
| def _parse_func(file_path: Path): | ||
| def _parse_func(file_path: Path) -> Any: | ||
| from lxml.etree import XMLParser, parse | ||
|
|
||
| xml_parser = XMLParser(huge_tree=True) | ||
|
|
@@ -59,13 +59,22 @@ def parse_python_test_xml( | |
| test_xml_file_path: Path, | ||
| test_files: TestFiles, | ||
| test_config: TestConfig, | ||
| run_result: subprocess.CompletedProcess | None = None, | ||
| run_result: subprocess.CompletedProcess[str] | None = None, | ||
| ) -> TestResults: | ||
| from codeflash.verification.parse_test_output import resolve_test_file_from_class_path | ||
|
|
||
| test_results = TestResults() | ||
| if not test_xml_file_path.exists(): | ||
| logger.warning(f"No test results for {test_xml_file_path} found.") | ||
| if run_result is not None and run_result.returncode != 0: | ||
| stderr_snippet = (run_result.stderr or "")[:500] | ||
| stdout_snippet = (run_result.stdout or "")[:500] | ||
| logger.warning( | ||
| f"No test results for {test_xml_file_path} found. " | ||
| f"Subprocess exited with code {run_result.returncode}.\n" | ||
| f"stdout: {stdout_snippet}\nstderr: {stderr_snippet}" | ||
| ) | ||
| else: | ||
| logger.warning(f"No test results for {test_xml_file_path} found.") | ||
| console.rule() | ||
| return test_results | ||
| try: | ||
|
|
@@ -87,12 +96,7 @@ def parse_python_test_xml( | |
| ): | ||
| logger.info("Test failed to load, skipping it.") | ||
| if run_result is not None: | ||
| if isinstance(run_result.stdout, str) and isinstance(run_result.stderr, str): | ||
| logger.info(f"Test log - STDOUT : {run_result.stdout} \n STDERR : {run_result.stderr}") | ||
| else: | ||
| logger.info( | ||
| f"Test log - STDOUT : {run_result.stdout.decode()} \n STDERR : {run_result.stderr.decode()}" | ||
| ) | ||
| logger.info(f"Test log - STDOUT : {run_result.stdout} \n STDERR : {run_result.stderr}") | ||
| return test_results | ||
|
|
||
| test_class_path = testcase.classname | ||
|
|
@@ -159,7 +163,7 @@ def parse_python_test_xml( | |
| sys_stdout = testcase.system_out or "" | ||
|
|
||
| begin_matches = list(matches_re_start.finditer(sys_stdout)) | ||
| end_matches: dict[tuple, re.Match] = {} | ||
| end_matches: dict[tuple[str, ...], re.Match[str]] = {} | ||
| for match in matches_re_end.finditer(sys_stdout): | ||
| groups = match.groups() | ||
| if len(groups[5].split(":")) > 1: | ||
|
|
@@ -234,11 +238,5 @@ def parse_python_test_xml( | |
| f"Tests '{[test_file.original_file_path for test_file in test_files.test_files]}' failed to run, skipping" | ||
| ) | ||
| if run_result is not None: | ||
| stdout, stderr = "", "" | ||
| try: | ||
| stdout = run_result.stdout.decode() | ||
| stderr = run_result.stderr.decode() | ||
| except AttributeError: | ||
| stdout = run_result.stderr | ||
| logger.debug(f"Test log - STDOUT : {stdout} \n STDERR : {stderr}") | ||
| logger.debug(f"Test log - STDOUT : {run_result.stdout} \n STDERR : {run_result.stderr}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you removed the try except here. are you sure there will be no exceptions? |
||
| return test_results | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 500? why not the entire string?