agronholm / agronholm/anyio

Please enable deterministic scheduling in the pytest plugin under Trio

未關閉
#581 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
2.5k
分支
260
平均合併
1 天 8 小時
30 天內合併 PR
17

描述

### 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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。