pytest
pytest copied to clipboard
Generalize `PYTEST_CURRENT_TEST` for threading
Part of https://github.com/pytest-dev/pytest/issues/13768.
I'm starting to work earnestly on https://github.com/pytest-dev/pytest/issues/13768, and figured I would start with a relatively simple fix + some general work for threading tests.
If we really cared about making PYTEST_CURRENT_TEST as good as it could be, then we could track a stack of pushes/pops to PYTEST_CURRENT_TEST, and when a pop occurs, we set it to the most-recent value on the stack instead of setting it to None. This would ensure that PYTEST_CURRENT_TEST always has a value when pytest is running, and is always "a test that is currently running", though there may be multiple currently-running tests. I am happy to implement this if you guys would prefer!