Uncertain finalizer ordering when using pytest indirect parametrize
0 reputation · 21 Apr 2022, 18:56 UTC
The goal is to determine how finalizers registered in an indirect parametrize fixture are ordered relative to other fixture finalizers and the test body. In indirect parametrize, a fixture supplies parameter values, and it may call request.addfinalizer to clean up. However, the exact sequence of finalizer execution is not explicitly documented, and it appears to depend on the registration order and fixture scopes.
Because the ordering can affect shared state, side‑effects, and test reliability, understanding the behavior is critical for writing deterministic tests that involve indirect parametrization, autouse fixtures, and xfail markers.
Which ordering guarantees, if any, does pytest provide for finalizers registered in an indirect parametrize fixture versus those registered in other fixtures? Can we influence the ordering deterministically, for example by adjusting fixture scopes or the order in which finalizers are added?