pytest-trio
pytest-trio copied to clipboard
synchronous fixture setup and teardown
Mainly fixes #137, by making fixtures setup and teardown synchronous Related issues and discussions:
- #57.
- It looks like we had figured some pitfalls with the concurrent version but we've been able to work around it so far.
- #59
- If the fixtures setup are synchronous, it should be easier to implement the separate
Contextapproach
- If the fixtures setup are synchronous, it should be easier to implement the separate
Implementation details
- I created a topological sort of all fixture dependencies for each test, and set them up synchronously, and then tear them down synchronously in a reverse order, by waiting for the 'previous' or 'next' fixture in the topology
- njsmith mentioned here that we can record the order of fixture construction from pytest - but I'm not sure if this is necessary? I was thinking we can create our own order, as long as it respects the dependency order, but I might be missing something, so let me know if this ordering is not enough to cover all cases!
- I added a test that tests for the
contextvarnot intertwining with each other- I also verified that this fails flakily without this diff.
Concerns
- This change might impact user experience, especially users that sets up i/o heavy fixtures.
This is my first PR, want to double check if I've done the complete checklist
- I installed pre-commit with config file in the trio repo since there doesn't seem to be one in this repo.
- I ended up getting warning for
asendfromcodespell, so I just disabledcodespelland committed without thecodespellcheck
- I ended up getting warning for
- I ran pytest with
PYTHONPATH="pytest-trio" pytest pytest-trioand I received 2 xfailed, and 1 warning.- I think the 2 xfailed are expected, since these 2 are indeed marked as xfail
- I can also see the warning when running pytest without setting the
PYTHONPATH
Let me know if I'm missing anything, would appreciate any feedback :D