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

Manually merged
github merged 1 commit from gh-pr/557/head into gh-pr/557/base 2026-11-26 09:08:26 +00:00
Owner

@⁠ddddddddwp on GitHub · 2026-11-24 08:02 UTC · original
ddddddddwp:fix/semantic-parallel-initializer → main · +38 −3 · 2 files · 1 commits · merged 2026-11-24 08:54 UTC

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.

**@⁠ddddddddwp** on GitHub · 2026-11-24 08:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/557) `ddddddddwp:fix/semantic-parallel-initializer` → `main` · +38 −3 · 2 files · 1 commits · merged 2026-11-24 08:54 UTC 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.
`python -m unittest pkg.__init__` imports pkg and then executes the same file again as
pkg.__init__, so a registration in the initializer happens twice in the -j 2 worker while
discover imports it once. Hand unittest the package name instead; module_path() still
resolves the initializer, so the largest-file-first order is unchanged.

A suite whose only module is an empty package initializer reported "1 files, 0 tests, 0
files failed" and exit 0 in parallel mode, where -j 1 (discover) exits 5. A run where every
job ran no tests now prints "no tests ran" and exits 1; an empty initializer next to real
tests is still fine because those count.

Both new cases in tests/test_run_semantic_tests.py fail against the previous script.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:08:25 +00:00
github manually merged commit 66dac0d938 into gh-pr/557/base 2026-11-26 09:08:26 +00:00
Author
Owner

@⁠Dezmonius on GitHub · 2026-11-24 08:17 UTC · original

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).

**@⁠Dezmonius** on GitHub · 2026-11-24 08:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/557#issuecomment-7125959026) 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).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 08:54 UTC · original

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).

**@⁠QemmHD** on GitHub · 2026-11-24 08:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/557#issuecomment-7126707000) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.