Session fixture keeps frames of other fixtures alive #2981
Comments
The leak was caused by the (unused) `FixtureRequest._fixture_values` cache. This was introduced because the `partial` object (created to call FixtureDef.finish() bound with the Request) is kept alive through the entire session when a function-scoped fixture depends on a session-scoped (or higher) fixture because of the nested `addfinalizer` calls. FixtureDef.finish() started receiving a request object in order to obtain the proper hook proxy object (pytest-dev#2127), but this does not seem useful at all in practice because `pytest_fixture_post_finalizer` will be called with the `request` object of the moment the fixture value was *created*, not the request object active when the fixture value is being destroyed. We should probably deprecate/remove the request parameter from `pytest_fixture_post_finalizer`. Fix pytest-dev#2981
Just ran the fix from #3030 locally, this also fixes an issue we encountered where our connections to postgresql were not closed, resulting in: Just for anyone else coming across this issue. Thanks @nicoddemus and the rest of the pytest team for all the work you do. |
Thanks @JacobSMoller for testing the PR! Glad this fixed your problem, but I would recommend regardless to explicitly close your connections and do not rely on the garbage collector for that. |
@nicoddemus just wanted to say thanks for your work on this! We'll be upgrading immediately and will let you know if we run into any issues. |
Consider this test file:
This fails with:
So for some reason the object created in
fix
is being kept alive aftertest1
has finished. This is caused bysession_fix
and can be verified by changingtest1
to no longer requiresession_fix
in which case both tests pass.This seems to reproduce the errors reported in #2968 and #2970 because both tests pass in😓
3.2.5
.The text was updated successfully, but these errors were encountered: