-
Notifications
You must be signed in to change notification settings - Fork 347
Add support for db fixture (test inside transaction) for asyncio tests #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
tox.ini
Outdated
@@ -10,6 +10,7 @@ envlist = | |||
[testenv] | |||
dependency_groups = | |||
testing | |||
!dj42: async |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a bug in my CI change.... 🧐 -- this should have failed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, @lode-braced can you please sync with main
once more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
... and fixed the resulting linting issue too ;)
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.