Commit 8341afe
authored
fix(tests): clean up sys.modules pollution in training fixtures (#2168)
Two cooperating fixture bugs caused order-dependent failures in
tests/unit_tests/training/:
1. test_timers.py:67 — `sys.modules["torch.distributed"] = dist_stub`
bypassed pytest's monkeypatch finalizer, leaking the stub for the
rest of the session. Any later test that imported torchao failed
with `ModuleNotFoundError: No module named 'torch.distributed.<X>';
'torch.distributed' is not a package`. Fixed by switching to
`monkeypatch.setitem(sys.modules, ...)` which is auto-reverted.
2. test_train_ft_mlflow_logging.py:_install_fake_wandb — the fake
wandb stub had `__spec__ = None`, so accelerate's
`importlib.util.find_spec("wandb")` raised
`ValueError: wandb.__spec__ is None`, breaking the test in
isolation. Fixed by setting a valid ModuleSpec via
`importlib.util.spec_from_loader`.
Verified: `pytest tests/unit_tests/training/` 55 passed (previously
2 failed, both fixture bugs visible).
Signed-off-by: Robert Luke <code@robertluke.net>1 parent 660ed94 commit 8341afe
2 files changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
0 commit comments