Description
Until not long ago Testdir.__init__
would set os.environ
directly, then it was changed to use MonkeyPatch
, and in master currently also sets some vars ($HOME
) only during inner runs, e.g. within runpytest
etc.
This was changed in features via #6219 most recently, which I consider kind of a regression to the behavior in master (initially I've done #6219 in a different way, addressing the issue that an outer monkeypatch gets not used, but then it got dragged into a simpler direction).
One issue with the current method is for example that e.g. pytest itself might be affected by this, since the patching is still active during teardown, and so e.g. the terminal plugin might be affected by it.
I'm not sure if $HOME
etc should get only set "magically" during inner runs, but I think it makes sense to couple the patching to the test "call" phase as much as possible.
One approach for this might be to use pytest_runtest_call
for this, which I've prototyped in blueyed#192.
But maybe there's a better method that would ensure a fixture (testdir
) gets teared down before the terminal reporter (and other plugins) get called for the test report?
(Also changing os.environ
during __init__
does not feel right to me - although given that this is a class to be used primarily as a fixture, but still.)