Smallest possible change to bump to Pydantic 2.x#15
Smallest possible change to bump to Pydantic 2.x#15charles-dyfis-net wants to merge 5 commits intojoeblackwaslike:simplefrom
Conversation
This leaves in place usage of several Pydantic 1.x-isms, which will need to be excised before Pydantic 3.x can be supported.
dabe406 to
62619eb
Compare
| "pytest-asyncio~=0.23.6", | ||
| # "pytest-asyncio~=0.20.3", | ||
| "pytest-asyncio @ https://github.com/joeblackwaslike/pytest-asyncio/releases/download/v0.20.4.dev42/pytest_asyncio-0.20.4.dev42-py3-none-any.whl", | ||
| # "pytest-asyncio @ https://github.com/joeblackwaslike/pytest-asyncio/releases/download/v0.20.4.dev42/pytest_asyncio-0.20.4.dev42-py3-none-any.whl", |
There was a problem hiding this comment.
this forked dependency is essential. pytest-asyncio has a longstanding bug they refuse to fix with context propagation which breaks async fixtures in pytest. The problem was that async fixtures that yield were having their finalizers run in a separate asyncio task that did not preserve contextvars.
I was able to fork this pytest plugin and fix that, and for the first time ever I saw async generator fixtures work under pytest. It felt magical. The upstream repo is not interested in solving the problem in this way, they would rather not solve it.
The last time I checked, my fork was the only version of pytest-asyncio that addresses this bug, and without it the tests fail due to an async fixture not propagating its context. Feel free to review my changes in the following repo: https://github.com/joeblackwaslike/pytest-asyncio
| "ignore:.*Field .* has conflict with protected namespace \"model_\".*:UserWarning", | ||
| ] | ||
| asyncio_mode = "auto" | ||
| py311_task = true |
There was a problem hiding this comment.
this is a toggle i created to activate the patch that fixes everything, so that behavior has to be explicitly opted into. you need to include it.
|
|
||
| [tool.pytest.ini_options] | ||
| addopts = "-rsx --tb=short --loop-scope session" | ||
| addopts = "-rsx --tb=short" |
There was a problem hiding this comment.
loop-scope is a new option i've added which parameterizes the scope of the event-loop fixture. Sharing the same event loop for the entire pytest session allows async fixtures to work at higher scopes.
| pytest -v -rsx --tb=short --asyncio-mode=auto --py311-task true --loop-scope session {posargs} tests | ||
| pytest -v -rsx --tb=short --asyncio-mode=auto {posargs} tests | ||
|
|
||
| [testenv:q183] | ||
| commands = | ||
| pdm install --dev | ||
| pip install aiofiles==23.2.1 blinker==1.5 click==8.1.7 flask==2.2.1 quart==0.18.3 werkzeug==2.2.0 jinja2==3.1.2 | ||
| pytest -v -rsx --tb=short --asyncio-mode=auto --py311-task true --loop-scope session {posargs} tests No newline at end of file |
There was a problem hiding this comment.
these options need to remain for things to keep working when run from tox
|



Addressing #14.
This leaves in place usage of several Pydantic 1.x-isms, which will need to be excised before Pydantic 3.x can be supported.