Commit b76d119
committed
[monarch] Introduce pytest marker to isolate tests in subprocess
NB: this is mostly vibe-coded since I'm not really familiar with pytest's internals.
This diff adds a new pytest marker `pytest.mark.spawn_isolate(timeout=..., env=...)` that provides similar functionality as the `pytest-isolate` package, except that it launches subprocesses by spawning them rather than forking (since the latter is incompatible with torch). Output from the child process is continuously piped back to the parent process so that if the child exits unexpectedly, we can still observe what happened. Child output is marked clearly, surrounded by orange headers/footers that look like:
```
vvvvvvv spawn_isolate FAIL for {test name} (child output) vvvvvvv
{child output}
^^^^^ end spawn_isolate FAIL for {test name} (child output) ^^^^^
```
The contents of `{child output}` are colored tan where it otherwise would have been white to easily distinguish where the child output starts and stops, but it maintains any explicit coloration set by pytest.
There are some tests where this marker is necessary -- for example, `test_debugger.py` requires each test to be isolated because each test needs to independently reconfigure/make assertions about the global debug controller actor.
However, I would further argue that this marker should be used for most or all of our tests. For better or worse, monarch makes substantial use of global state, and it is too easy for one test to interfere with another test in the same process. For example, a test failure could put a global actor into a bad/failed state in a way that is consistent with the intended behavior of the system; however, other tests in the same process that try to use this global actor would then fail, which just adds noise to an already difficult debugging experience.
Moreover, running each test in its own subprocess will make it much easier to ensure that resources aren't leaked across tests.
Differential Revision: [D88395512](https://our.internmc.facebook.com/intern/diff/D88395512/)
ghstack-source-id: 327474510
Pull Request resolved: #20761 parent 2cbbe16 commit b76d119
3 files changed
+486
-67
lines changed
0 commit comments