[PR #662] [MERGED] run_semantic_tests: count the tests from unittest, not from the merged output #702

Closed
opened 2026-11-26 20:18:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/662
Author: @Mby159
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/semantic-ran-count-stream


📝 Commits (3)

  • 23b190b run_semantic_tests: count the tests from unittest, not from the merged output
  • 7d184af semantic tests: count from unittest's own summary
  • f48c2b2 semantic tests: count from unittest's result object

📊 Changes

2 files changed (+100 additions, -17 deletions)

View changed files

📝 scripts/run_semantic_tests.py (+51 -17)
📝 tests/test_run_semantic_tests.py (+49 -0)

📄 Description

Claim: SEMANTIC-RAN-COUNT-STREAM

The count came from the wrong stream. scripts/run_semantic_tests.py counted a module's tests by scanning the
merged stdout+stderr for the first line that reads Ran N tests in, so a test that printed such a line itself could
be counted instead of unittest's own summary. @Dezmonius reported this on #14
(#issuecomment-7128362815) and offered to take it if it were added to Open work; the Open work table cannot be
edited by a contributor (GitHub answers 403 Must have admin rights to Repository), so I took it rather than leave
it unowned. His finding is the starting point.

Reproduced on main 21625bca8. A module whose test prints Ran 0 tests in 0.000s and flushes it was reported
as 1 files, 0 tests, 0 files failed and no tests ran, and the runner exited 1, although the module ran its
tests and passed. Which line won depended on stdout buffering: a test that does not flush lands its line after
unittest's summary (the count is right), a test that does flush lands it first (the count is 0). Neither the first
nor the last match is reliable.

The fix. unittest writes its own summary (Ran N tests in X s) and its NO TESTS RAN to stderr; a test's own
output goes to stdout. The runner now captures the two streams apart and counts from stderr. The merged text is
still what a failing module prints, and the timeout path keeps both streams.

Testing. Windows 11 10.0.29712, CPython 3.13.17:

  • the reproduction above now reports 1 files, 1 tests, 0 files failed and exits 0;
  • python -I tests/test_run_semantic_tests.py: 20 tests, OK. The file gained a case that covers both orders, a test
    that flushes its line and a test that prints it at process exit;
  • on the repository's own tests/semantic, one subset counted the same in parallel and in serial: -j 4 gave
    4 files, 18 tests, 0 files failed, -j 1 (unittest discover) gave Ran 18 tests.

No game files, no GPU and no particular hardware: the runner and its test file are the check.

AI-assisted (MiniMax Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/662 **Author:** [@Mby159](https://github.com/Mby159) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/semantic-ran-count-stream` --- ### 📝 Commits (3) - [`23b190b`](https://github.com/ubiquitarianism/leonida/commit/23b190b19ed0d5ec26baf08c88610333168ac424) run_semantic_tests: count the tests from unittest, not from the merged output - [`7d184af`](https://github.com/ubiquitarianism/leonida/commit/7d184af582458bff84bfe6be65933d671891d993) semantic tests: count from unittest's own summary - [`f48c2b2`](https://github.com/ubiquitarianism/leonida/commit/f48c2b2a352394e835ae746024990970f1112c29) semantic tests: count from unittest's result object ### 📊 Changes **2 files changed** (+100 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `scripts/run_semantic_tests.py` (+51 -17) 📝 `tests/test_run_semantic_tests.py` (+49 -0) </details> ### 📄 Description Claim: SEMANTIC-RAN-COUNT-STREAM **The count came from the wrong stream.** `scripts/run_semantic_tests.py` counted a module's tests by scanning the merged stdout+stderr for the first line that reads `Ran N tests in`, so a test that printed such a line itself could be counted instead of unittest's own summary. @Dezmonius reported this on #14 (#issuecomment-7128362815) and offered to take it if it were added to Open work; the Open work table cannot be edited by a contributor (GitHub answers `403 Must have admin rights to Repository`), so I took it rather than leave it unowned. His finding is the starting point. **Reproduced on `main` `21625bca8`.** A module whose test prints `Ran 0 tests in 0.000s` and flushes it was reported as `1 files, 0 tests, 0 files failed` and `no tests ran`, and the runner exited 1, although the module ran its tests and passed. Which line won depended on stdout buffering: a test that does not flush lands its line after unittest's summary (the count is right), a test that does flush lands it first (the count is 0). Neither the first nor the last match is reliable. **The fix.** unittest writes its own summary (`Ran N tests in X s`) and its `NO TESTS RAN` to stderr; a test's own output goes to stdout. The runner now captures the two streams apart and counts from stderr. The merged text is still what a failing module prints, and the timeout path keeps both streams. **Testing.** Windows 11 10.0.29712, CPython 3.13.17: - the reproduction above now reports `1 files, 1 tests, 0 files failed` and exits 0; - `python -I tests/test_run_semantic_tests.py`: 20 tests, OK. The file gained a case that covers both orders, a test that flushes its line and a test that prints it at process exit; - on the repository's own `tests/semantic`, one subset counted the same in parallel and in serial: `-j 4` gave `4 files, 18 tests, 0 files failed`, `-j 1` (unittest discover) gave `Ran 18 tests`. No game files, no GPU and no particular hardware: the runner and its test file are the check. AI-assisted (MiniMax Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:46 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#702
No description provided.