run_semantic_tests: a package initializer runs once, and a run with no tests fails #557

Merged
ddddddddwp merged 1 commit from upstream-pr/557 into main 2026-11-24 08:54:16 +00:00
ddddddddwp commented 2026-11-24 08:02:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ddddddddwp on 2026-11-24T08:02:22Z.


Finding: the 2026-11-24 07:17 comment in #14 (Dezmonius), claimed there.

What

Two serial/parallel differences in scripts/run_semantic_tests.py:

  1. A package initializer ran twice in its -j 2 worker. test_modules() lists pkg.__init__, and
    python -m unittest pkg.__init__ imports pkg and then executes the same file again as pkg.__init__. A
    registration in the initializer therefore happened twice (['pkg', 'pkg.__init__']) while -j 1 (discover)
    imports it once. run_module() now hands unittest the package name (pkg); module_path() still resolves the
    initializer's path, so the largest-file-first order is unchanged and the failure still names pkg.__init__.

  2. A run with no tests was green in parallel. With only an empty pkg/__init__.py, -j 1 exits 5 but -j 2
    printed 1 files, 0 tests, 0 files failed and exited 0. A parallel run where every job ran no tests now prints
    no tests ran in <dir> and exits 1. An empty initializer beside real tests is still accepted (the existing
    exit 5/NO TESTS RAN mapping), because the run's total is above zero.

Tests

tests/test_run_semantic_tests.py, two new cases:

  • test_package_initializer_runs_once_in_parallel: a pkg/__init__.py that appends __name__ and asserts the list
    is ['pkg'], in -j 1 and -j 2.
  • test_empty_package_alone_is_not_a_false_green: only an empty pkg/__init__.py, both modes must exit nonzero and
    the parallel output names the reason.

Both fail against the previous script (jobs=2 subtest) and pass now:

$ python -I tests/test_run_semantic_tests.py
Ran 19 tests in 3.5s
OK

Manual fixture from the finding, with the new script: -j 2 gives 1 files, 1 tests, 0 files failed (exit 0), and
the empty package gives no tests ran in ... (exit 1, where the old script exited 0).

macOS arm64, CPython 3.14.10, standard library only. No game files, no GPU, nothing online.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5468360148 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/557). Originally posted by [ddddddddwp](https://github.com/ddddddddwp) on 2026-11-24T08:02:22Z. --- Finding: the 2026-11-24 07:17 comment in #14 (Dezmonius), claimed there. ## What Two serial/parallel differences in `scripts/run_semantic_tests.py`: 1. **A package initializer ran twice in its `-j 2` worker.** `test_modules()` lists `pkg.__init__`, and `python -m unittest pkg.__init__` imports `pkg` and then executes the same file again as `pkg.__init__`. A registration in the initializer therefore happened twice (`['pkg', 'pkg.__init__']`) while `-j 1` (discover) imports it once. `run_module()` now hands unittest the package name (`pkg`); `module_path()` still resolves the initializer's path, so the largest-file-first order is unchanged and the failure still names `pkg.__init__`. 2. **A run with no tests was green in parallel.** With only an empty `pkg/__init__.py`, `-j 1` exits 5 but `-j 2` printed `1 files, 0 tests, 0 files failed` and exited 0. A parallel run where every job ran no tests now prints `no tests ran in <dir>` and exits 1. An empty initializer beside real tests is still accepted (the existing `exit 5`/`NO TESTS RAN` mapping), because the run's total is above zero. ## Tests `tests/test_run_semantic_tests.py`, two new cases: - `test_package_initializer_runs_once_in_parallel`: a `pkg/__init__.py` that appends `__name__` and asserts the list is `['pkg']`, in `-j 1` and `-j 2`. - `test_empty_package_alone_is_not_a_false_green`: only an empty `pkg/__init__.py`, both modes must exit nonzero and the parallel output names the reason. Both fail against the previous script (`jobs=2` subtest) and pass now: ``` $ python -I tests/test_run_semantic_tests.py Ran 19 tests in 3.5s OK ``` Manual fixture from the finding, with the new script: `-j 2` gives `1 files, 1 tests, 0 files failed` (exit 0), and the empty package gives `no tests ran in ...` (exit 1, where the old script exited 0). macOS arm64, CPython 3.14.10, standard library only. No game files, no GPU, nothing online. AI-assisted.
Dezmonius commented 2026-11-24 08:17:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Dezmonius on 2026-11-24T08:17:39Z.


Thanks for carrying over the finding. Independent Windows check at 66dac0d (CPython 3.14.7): all 19 runner tests pass. The original two fixtures confirm the fixes at -j 2 --timeout 5: the initializer runs once, and the empty suite exits 1. An empty initializer alongside a real test still passes. A hanging initializer at --timeout 2 reports the timeout and the independent healthy module still runs.

One new exit-code regression: total == 0 relies on the first Ran … tests in line from combined subprocess output. A test module can emit that line before unittest emits its own summary. Put this in an otherwise empty suite as test_pass.py:

import unittest

print("Ran 0 tests in 0.000s", flush=True)

class T(unittest.TestCase):
    def test_pass(self):
        self.assertTrue(True)

On Windows with both CPython 3.12.10 and 3.14.7, -j 1 --timeout 5 exits 0, and -j 2 --timeout 5 on this PR prints unittest's Ran 1 test and OK, then exits 1 with no tests ran. On main 1c93c86, the same parallel command exits 0 despite the inaccurate summary count. Could the new empty-run decision use the subprocess's explicit no-tests outcome (exit 5 for the empty fixture on both tested versions) separately from the count scraped for display?

CPU-only synthetic fixtures. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7125959026 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/557#issuecomment-7125959026). Originally posted by [Dezmonius](https://github.com/Dezmonius) on 2026-11-24T08:17:39Z. --- Thanks for carrying over the finding. Independent Windows check at `66dac0d` (CPython 3.14.7): all 19 runner tests pass. The original two fixtures confirm the fixes at `-j 2 --timeout 5`: the initializer runs once, and the empty suite exits 1. An empty initializer alongside a real test still passes. A hanging initializer at `--timeout 2` reports the timeout and the independent healthy module still runs. One new exit-code regression: `total == 0` relies on the first `Ran … tests in` line from combined subprocess output. A test module can emit that line before unittest emits its own summary. Put this in an otherwise empty suite as `test_pass.py`: ```python import unittest print("Ran 0 tests in 0.000s", flush=True) class T(unittest.TestCase): def test_pass(self): self.assertTrue(True) ``` On Windows with both CPython 3.12.10 and 3.14.7, `-j 1 --timeout 5` exits 0, and `-j 2 --timeout 5` on this PR prints unittest's `Ran 1 test` and `OK`, then exits 1 with `no tests ran`. On main `1c93c86`, the same parallel command exits 0 despite the inaccurate summary count. Could the new empty-run decision use the subprocess's explicit no-tests outcome (exit 5 for the empty fixture on both tested versions) separately from the count scraped for display? CPU-only synthetic fixtures. AI-assisted (Codex).
QemmHD commented 2026-11-24 08:54:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T08:54:14Z.


Merging. Why merged: a package initializer no longer runs twice, and a semantic run in which no test ran no longer counts as a pass.
Why it's good: on main 1c93c86: runner tests 17 -> 19; the full semantic run with the new runner still selects 465 files / 6108 tests; repo-consistency set 563 -> 565 (its own new tests), 0 failures.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7126707000 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/557#issuecomment-7126707000). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T08:54:14Z. --- Merging. Why merged: a package initializer no longer runs twice, and a semantic run in which no test ran no longer counts as a pass. Why it's good: on main 1c93c86: runner tests 17 -> 19; the full semantic run with the new runner still selects 465 files / 6108 tests; repo-consistency set 563 -> 565 (its own new tests), 0 failures. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!557
No description provided.