agronholm / agronholm/anyio

Please enable deterministic scheduling in the pytest plugin under Trio

Đang mở
#581 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
2.5k
Fork
260
Merge trung bình
2 ngày 8 giờ
Pull request đã merge (30 ngày)
19

Mô tả

### Things to check first

- [X] I have searched the existing issues and didn't find my feature already requested there

### Feature description

I request a pytest plugin feature to enable deterministic testing, similar to what is done under [pytest-trio](https://github.com/python-trio/pytest-trio). I do not see any easy way to do this for the asyncio backend.

I have made a [feature request in trio](https://github.com/python-trio/trio/issues/2675) to enable keywording of this as a backend feature, which is a far preferable way of implementing the same thing.

### Use case

Deterministic scheduling is very handy in many test scenarios. Trio allows somewhat-deterministic scheduling through monkey-patching its event loop generator to set `_ALLOW_DETERMINISTIC_SCHEDULING` and replacing its random-value generator with a seeded one. Both of which are done by `pytest-trio`, but not by the AnyIO pytest plugin. I say "somewhat-deterministic" because differences in thread timing based on CPU utilization can still introduce stochastic elements, even in fully mocked-up code.

AFAIK, it's not similarly easy to achieve deterministic-ish scheduling with asyncio, although I have seen code that injects additional jobs into the event loop to make a state machine of sorts. One thing that attracted me to AnyIO is to do deterministic (and non-performant) testing with `trio` and then use `asyncio+uvloop` in production.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.