Skip to content

Commit 9531d35

Browse files
Revert "use new pytest finalizer order teardown fix"
This reverts commit 91022425d40076f7cd78323467f4e056c7b9d716. the finalizer order is still not working as of pytest (@2607fe8b4706f). cf. pytest-dev/pytest#12134
1 parent 4c66b6a commit 9531d35

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

boa/test/plugin.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,33 @@ def pytest_collection_modifyitems(config, items):
5050
item.add_marker("gas_profile")
5151

5252

53+
_task_list = set()
54+
_stack = {} # preserve the original order of tasks
55+
_id = 0
56+
57+
5358
def pytest_fixture_setup(fixturedef, request):
59+
global _id
60+
task_id = _id
61+
_id += 1
62+
5463
ctx = boa.env.anchor()
64+
_stack[task_id] = ctx
65+
5566
ctx.__enter__()
5667

57-
def _finalize():
58-
ctx.__exit__(None, None, None)
68+
def finalize():
69+
_task_list.add(task_id)
70+
_work_task_list()
71+
72+
fixturedef.addfinalizer(finalize)
5973

60-
# this depends on pytest 8.2.0 for some cases where fixtures
61-
# used to be torn down out of order (fix introduced in
62-
# https://github.com/pytest-dev/pytest/pull/11833/)
63-
fixturedef.addfinalizer(_finalize)
74+
75+
def _work_task_list():
76+
while (task_id := next(reversed(_stack.keys()), None)) in _task_list:
77+
ctx = _stack.pop(task_id)
78+
_task_list.remove(task_id)
79+
ctx.__exit__(None, None, None)
6480

6581

6682
@pytest.hookimpl(hookwrapper=True)

0 commit comments

Comments
 (0)