pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

Add support for db fixture (test inside transaction) for asyncio tests

Open lode-braced opened this issue 5 months ago • 6 comments

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.

lode-braced avatar Aug 12 '25 08:08 lode-braced

@kingbuzzman CI and myself are now happy with where the branch is at, feel free to have a deeper look now.

lode-braced avatar Aug 12 '25 10:08 lode-braced

@lode-braced can you please sync with main, there are new CI rules

kingbuzzman avatar Aug 12 '25 15:08 kingbuzzman

@lode-braced can you please sync with main, there are new CI rules

Done!

lode-braced avatar Aug 12 '25 15:08 lode-braced

@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?

lode-braced avatar Aug 26 '25 13:08 lode-braced

@kingbuzzman Is there anything you need/someone else I should ping to get this reviewed further?

lode-braced avatar Sep 25 '25 07:09 lode-braced

Hey @lode-braced I haven't been ignoring you deliberately. I've been waiting for others to give some feedback, specially @bluetech

kingbuzzman avatar Dec 01 '25 11:12 kingbuzzman

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!

Artui avatar Dec 22 '25 21:12 Artui