Refactor Python test XML parsing into focused helpers and add direct parser coverage#2074
Closed
shreejaykurhade wants to merge 3 commits intocodeflash-ai:mainfrom
Closed
Refactor Python test XML parsing into focused helpers and add direct parser coverage#2074shreejaykurhade wants to merge 3 commits intocodeflash-ai:mainfrom
shreejaykurhade wants to merge 3 commits intocodeflash-ai:mainfrom
Conversation
…ce complexity and isolate wrapper-building concerns
7c8eb05 to
8e6b558
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors the Python test XML parsing flow used by parse_test_xml without changing intended behavior.
codeflash/verification/parse_test_output.py::parse_test_xml is only a thin delegator. The actual large parsing logic lives in codeflash/languages/python/parse_xml.py::parse_python_test_xml, and that function had grown to handle several concerns in one place:
XML loading and validation
failed unittest-loader handling
testcase name extraction
test file and test type resolution
timeout detection
stdout marker pairing
FunctionTestInvocation construction
empty-result logging
This made the parser harder to read, harder to review, and riskier to change.
What Changed
The parser is now split into smaller helpers with clearer responsibilities:
_load_python_test_xml
_is_failed_unittest_loader_case
_log_failed_unittest_loader_output
_extract_test_function_name
_resolve_test_file_path
_resolve_test_type
_did_testcase_time_out
_parse_python_test_case
_build_end_matches
_build_default_test_invocation
_build_marker_test_invocations
_log_empty_test_results
A small internal _ParsedPythonTestCase dataclass was also introduced to carry resolved testcase metadata between steps.
parse_python_test_xml() now acts as the orchestration layer for:
loading the XML
iterating suites/testcases
handling the unittest-loader special case
parsing testcase metadata
building invocations from stdout markers or the default fallback path
logging when no test results were produced
Why This Is Better
This improves maintainability by:
separating testcase resolution from marker parsing
reducing cognitive load in the main parser
localizing future changes to the smallest relevant helper
making the parser easier to test directly at the implementation seam
This is intended to be a behavior-preserving refactor, not a functional redesign.
Tests Added
Added direct parser coverage in tests/test_parse_python_test_xml.py for:
the fallback path when no stdout markers are present
the marker-based path that extracts invocation metadata, runtime, and stdout
These complement the existing higher-level coverage in:
tests/test_test_runner.py
tests/test_parse_test_output_regex.py
Typing
Added the missing return annotation for _parse_func(...) in codeflash/languages/python/parse_xml.py.
Validation
uv run pytest -q tests/test_parse_python_test_xml.py
uv run pytest -q tests/test_test_runner.py
uv run pytest -q tests/test_parse_test_output_regex.py
uv run pytest -q tests/test_parse_python_test_xml.py tests/test_test_runner.py tests/test_parse_test_output_regex.py
uv run ruff check codeflash/languages/python/parse_xml.py tests/test_parse_python_test_xml.py
uv run ruff check codeflash/languages/python/parse_xml.py tests/test_parse_python_test_xml.py --select ANN202
All checks passed. One environment-specific Windows pytest temp-dir cleanup warning still appears on exit, but it does not affect test outcomes.
Risk
Low. This change is a structural refactor of existing Python XML parsing logic with focused direct tests and existing runner-level coverage still passing.