pytest-trio icon indicating copy to clipboard operation
pytest-trio copied to clipboard

synchronous fixture setup and teardown

Open agnesnatasya opened this issue 2 years ago • 0 comments

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 Context approach

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 contextvar not 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 asend from codespell, so I just disabled codespell and committed without the codespell check
  • I ran pytest with PYTHONPATH="pytest-trio" pytest pytest-trio and 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

agnesnatasya avatar Oct 07 '23 14:10 agnesnatasya