harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4225harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4225PSEUDOCODE
BEGIN
// Objective // Build a standalone validator script that runs PyTest on a fixed test file // and verifies the results match the intended xfail/semi-pass semantics.
// INPUTS / CONFIGURATION TEST_FILE_PATH := "tests/unit/test_pytest_pass_fail.py" // default, not to be modified OPTIONAL_OVERRIDES := allow user to specify alternate path (e.g., via --test-path)
// OUTPUTS EXIT_CODE := integer REPORT := human-readable summary and diagnostics
// MAIN TASK FUNCTION main(): path <- obtain_path_from_args_or_default(TEST_FILE_PATH)
// 1) Run PyTest on the exact test file, without modifying it
CMD <- ["pytest", path]
RESULT <- run_subprocess(CMD) // capture stdout and stderr
OUTPUT <- RESULT.stdout + RESULT.stderr
// 2) Parse summary to count outcomes
COUNTS <- parse_summary(OUTPUT)
// COUNTS must provide:
// COUNTS.passed := number of tests reported as passed
// COUNTS.xfailed := number of tests reported as xfailed
// COUNTS.xpass := number of tests reported as XPASS (if any)
// 3) Validate expected semantics
IF COUNTS.passed == 1 AND COUNTS.xfailed == 1 AND COUNTS.xpass == 0 THEN
print "Validation successful: 1 passed, 1 xfailed, 0 XPASS"
print "Observed output:"
print OUTPUT
EXIT 0
ELSE
print "DIAGNOSTICS"
print "Observed counts -> passed:", COUNTS.passed, "xfailed:", COUNTS.xfailed, "XPASS:", COUNTS.xpass
print "PyTest output:"
print OUTPUT
EXIT 1
ENDIF
// 4) Helper: parse summary robustly across PyTest versions FUNCTION parse_summary(text): INITIALIZE counts: passed := 0, xfailed := 0, xpass := 0
// Strategy: scan summary sections for lines containing outcome tokens
// Common tokens to recognize (case-insensitive):
// "passed", "failed", "xfailed"/"xfail", "xpac"/"XPASS" (and variations)
FOR EACH line IN extract_lines(text):
LOWER <- convert_to_lowercase(line)
IF contains(LOWER, " passed") OR matches_pattern(LOWER, r"^\s*\d+\s+passed"):
N <- extract_number_before_token(line, "passed")
IF N IS NOT NULL THEN counts.passed <- max(counts.passed, N)
ENDIF
IF contains(LOWER, " xfailed") OR contains(LOWER, " xfail"):
N <- extract_number_before_token(line, "xfailed" OR "xfail")
IF N IS NOT NULL THEN counts.xfailed <- max(counts.xfailed, N)
ENDIF
IF contains(LOWER, " xpass") OR contains(LOWER, " xpass") OR contains(LOWER, " xpased"):
N <- extract_number_before_token(line, "xpass" OR "xpasse" OR "xpased")
IF N IS NOT NULL THEN counts.xpass <- max(counts.xpass, N)
ENDIF
ENDFOR
RETURN counts
END FUNCTION
// 5) OPTIONAL: usage guidance // Script should be invoked as: // python verify_pytest_behavior.py // Optionally allow overriding the test path with a flag (e.g., --test-path /path/to/file)
// 6) Non-functional constraints // - Implemented in Python 3 // - No external dependencies beyond standard library // - Stateless across runs; reads current PyTest results each execution // - Robust to minor formatting differences in PyTest summary
END