Refactor benchmark tests for cleanup_test_output#5402
Open
anushakamran06 wants to merge 1 commit into
Open
Conversation
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.
Motivation
benchmark/test_benchmark.pythe only test file for the benchmark harness has been broken since mid-2023 and currently cannot run at all. This was independently flagged in a note on #5136:This PR fixes the tests so the suite runs and passes again, and adds coverage for the
testdirbehavior that was never tested.Root cause: the tests were written against a 2023 version of
cleanup_test_output. The function has since changed in two ways the tests never tracked:cleanup_test_output(output)becamecleanup_test_output(output, testdir)when testdir-path scrubbing was added (replacing the full test directory path withtestdir.namein test output). Both existing tests still call it with one argument → immediateTypeError.====/----separator lines are truncated to====/----. That truncation was removed fromcleanup_test_outputafter the June 2023 commit that introduced it ("remove long ==--- lines to save tokens") and no longer exists in the function, so the assertion tests phantom behavior."Ran 5 tests in 0.003s\nOK"→"\nOK", but the current regexr"\bin \d+\.\d+s\b"only removes the timing substring, yielding"Ran 5 tests \nOK"(leading text and trailing space are preserved).Reproduction (on
main, from insidebenchmark/):Modifications
All changes are confined to
benchmark/test_benchmark.py. No production code is touched — the tests are updated to match the current, long-standing behavior ofcleanup_test_output.setUpproviding a realistictestdirPathmatching the harness layout (tmp.benchmarks/<date>/<lang>/exercises/practice/<exercise>), and passed it to every call."Ran 5 tests \nOK"per the actual regex behavior.====/----truncation test — that behavior no longer exists incleanup_test_output.testdir.namein output (this is what anonymizes absolute paths before test output is fed back to the LLM)Test inputs are built with f-strings off
str(self.testdir), so path-separator differences make the tests pass identically on Windows and POSIX.Tests
Note:
python -m unittest test_benchmarkmust be run from insidebenchmark/so thatbenchmark.py(which imports its sibling modulespromptsandplotsas top-level modules) resolves correctly. Running via pytest from the repo root resolvesbenchmarkto the package (benchmark/__init__.py) rather than the module and fails on import — a pre-existing quirk, noted under out-of-scope below.Impact
cleanup_test_outputis untouched.Out of scope (possible follow-ups)
benchmark/__init__.pyvsbenchmark.pyname collision that prevents running these tests via pytest with default import mode.benchmark.py(run_unit_testscommand selection,summarize_results), which currently has none.