Add support for db fixture (test inside transaction) for asyncio tests#1223
Add support for db fixture (test inside transaction) for asyncio tests#1223lode-braced wants to merge 29 commits intopytest-dev:mainfrom
Conversation
kingbuzzman
left a comment
There was a problem hiding this comment.
This is not a code review
From what I can briefly see; this looks great, i've personally had this issue come up, so happy you've taken this on!
|
@kingbuzzman CI and myself are now happy with where the branch is at, feel free to have a deeper look now. |
|
@lode-braced can you please sync with |
Done! |
kingbuzzman
left a comment
There was a problem hiding this comment.
5/8 files reviewed. More to follow.
…c_fixture # Conflicts: # pytest_django/plugin.py
|
@kingbuzzman apologies for the silence, I've been on holiday. The PR should have addressed your remarks where possible, and I've removed the sync code, to be done in another PR once we get this one done. Can you have another look and close topics as needed? |
|
@kingbuzzman Is there anything you need/someone else I should ping to get this reviewed further? |
|
Hey @lode-braced I haven't been ignoring you deliberately. I've been waiting for others to give some feedback, specially @bluetech |
|
Hey, we're running in some similar issues with the combination of pytest-asyncio, pytest-django and pytest-xdist. Any idea when this PR can be expected to be reviewed/approved? Thanks! |
In using and debugging pytest-django with async tests & fixtures, I ended up hacking together a way to get the db fixture working by enabling the transaction in the sync to async executor thread in which async orm queries run.
This PR aims to integrate that hack as actual functionality into pytest-django.
The async work is done, I also worked to refine the sync side database access: not allowing db access to threads other than the main thread which is running the test (& transaction). That second part is causing some test failures I've yet been unable to fix on 3.9 & django 4.2, will try to fix or drop it from the PR.
edit: I managed to fix the issue with the test failures: my monkeypatches were dropping the self attribute. Ready for review.
Suggestions & feedback welcome.