python-trio / pytest-trio

Pytest plugin for trio
Other
54 stars 25 forks source link

Refactor everything and use the same logic as pytest-anyio #147

Open jakkdl opened 3 weeks ago

jakkdl commented 3 weeks ago

https://anyio.readthedocs.io/en/stable/testing.html has a much cleaner implementation at a fraction of the code size: https://github.com/agronholm/anyio/blob/master/src/anyio/pytest_plugin.py

Discussions in Gitter also suggests people prefer running pytest-anyio in trio mode over directly running pytest-trio.

This would also resolve #137, #124, probably #123, #89, #57, and surely a whole host of other issues.

EDIT: it would also resolve the problem of yield raising trio.Cancelled and making teardown not get executed unless it's inside a finally: https://pytest-trio.readthedocs.io/en/stable/reference.html#an-important-note-about-yield-fixtures

jakkdl commented 1 week ago

I'm making solid progress on this, but pytest-anyio does not support clocks/instruments (https://github.com/agronholm/anyio/issues/260), so will have to add that functionality

jakkdl commented 1 week ago

I'm making solid progress on this, but pytest-anyio does not support clocks/instruments (agronholm/anyio#260), so will have to add that functionality

okay this was pretty trivial.

  1. But #137 needs to be "resolved" (which means removing functionality and their corresponding tests) as the pytest-anyio test runner does not support it, and adding it would be messy (and perhaps bad).
  2. pytest-anyio currently does not run sync fixtures in the same context https://anyio.readthedocs.io/en/stable/testing.html#context-variable-propagation and there may be issues when doing that + differently scoped fixtures. I'll probably blaze ahead and run all fixtures, async or not, in the same context and see if issues do pop up later on - any current test suites using pytest-trio will only be using function-scoped fixtures anyway.