mikebridge opened a new pull request, #44178:
URL: https://github.com/apache/superset/pull/44178

   ### SUMMARY
   
   The `unit-tests (current)` job in `Python-Unit` has been getting killed at 
its 30-minute `timeout-minutes` wall even though every test passes. The serial 
suite has grown to ~27–28 minutes, so the *trailing* steps (the 100%-coverage 
gates and the codecov upload) no longer fit on an ordinary slow-runner day:
   
   | run | `Python unit tests` step | then | total |
   |---|---|---|---|
   | passing | 26m45s ✅ | coverage 1m27s + upload 0m20s | 29m24s — 36 s to 
spare |
   | killed | 28m04s ✅ | killed *during* the coverage gate | 30m21s |
   | killed | 27m43s ✅ | coverage ✅, killed *during* codecov upload | 30m11s |
   
   Same tree all three times; the only variable was ~1.3 min of runner speed. 
Master's own runs take 25–29 min, so the whole repo sits at 85–97% of the 
budget. On 2026-09-11 alone this killed five otherwise-green PR runs. The step 
ran `pytest` single-process with coverage instrumentation on, and 
`pytest-xdist` wasn't installed.
   
   This PR runs the step with **`pytest -n auto --dist loadfile`**:
   
   - `--dist loadfile` keeps every test in a file on one worker, so 
module-scoped fixture state is preserved.
   - `pytest-cov` combines the per-worker data into the single `.coverage` that 
the later 100%-coverage gates and the codecov upload already read — verified: 
one combined, fully populated data file, no leftover fragments.
   - The two short 100%-coverage gates stay serial (tiny subtrees; xdist 
startup would cost more than it saves). `timeout-minutes` is unchanged on 
purpose: with the main step at roughly 8–9 min on the 4-core runners it now has 
~3× headroom instead of 36 seconds.
   - Lockfile delta is exactly `pytest-xdist==3.8.0` plus its one dependency 
`execnet==2.1.2` (regenerated with `scripts/uv-pip-compile.sh`).
   
   Parallelism exposed two latent problems in the suite itself. Both are fixed 
here, each with a fail-without / pass-with control:
   
   1. **Non-deterministic collection order.** 
`tests/unit_tests/commands/report/base_test.py` parametrized over Python 
`set`s, so every worker collected the same ids in a different per-process hash 
order and xdist aborted with *"Different tests were collected between gw4 and 
gw2"*. Diffing full collections under two `PYTHONHASHSEED` values showed it was 
the **only** such file out of 15,132 tests. Sets → tuples, with a comment so it 
doesn't get tidied back.
   
   2. **A hidden import-order dependency (a flake class, not a one-off).** 
`test_get_sql_results_oauth2` runs under `@freeze_time` and happened to be the 
first lazy importer of the engine-spec modules on its worker. 
`clickhouse_connect` reads the local timezone via `dateutil` **at import 
time**, which raises `AttributeError` under a frozen clock; Superset's 
`clickhouse.py` guard only catches `ImportError`. Serially, some earlier test 
had always paid that import outside `freeze_time`, hiding the dependency. 
**Fifteen** unit-test files use `freeze_time`, so on xdist whichever is first 
on its worker fails — a flake that moves with worker assignment. A 
session-scoped autouse fixture in `tests/unit_tests/conftest.py` now pre-loads 
the engine specs once per worker before any test can freeze the clock, giving 
every worker the import state a serial run reached by accident. Control: on a 
cold process the test fails with the exact `AttributeError` without the fixture 
and passes with it.
   
   Local result (8 workers, coverage on, `TZ=UTC`): **15,126 passed, 5 skipped, 
2 xfailed, 0 failed in 3m38s** — versus ~27 min serial.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A (CI configuration).
   
   ### TESTING INSTRUCTIONS
   
   1. The `Python-Unit` workflow on this PR is the primary test — `unit-tests 
(current)` should finish well inside the timeout with all lanes green and 
coverage uploaded.
   2. Locally, with the dev requirements installed:
      ```bash
      SUPERSET_TESTENV=true SUPERSET_SECRET_KEY=not-a-secret \
      pytest -n auto --dist loadfile --cov=superset --cov-report= 
./tests/common ./tests/unit_tests --cache-clear
      ```
      then `coverage report` shows a populated combined file.
   3. Collection determinism: `pytest --collect-only -q tests/unit_tests` under 
`PYTHONHASHSEED=1` and `=2` produces identical output.
   4. The freeze_time control: stash the `conftest.py` change and run `pytest 
tests/unit_tests/sql_lab_test.py::test_get_sql_results_oauth2` in a fresh 
process — it fails with `AttributeError: 'NoneType' object has no attribute 
'replace'` from `dateutil/tz`; restore the change and it passes.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01EA4MGEkUcDpyLReqjQBhPy
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to