pytest-dev / pytest-dev/pytest-django
mailoutbox doesn't work correctly with celery_worker
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I found a problem, that any of my tests in parametrize not get in mailoutbox enough messages that were sent by .delay as celery tasks. So, I should do at least time.sleep(1) to get remaining messages to mailoutbox before checking its lenght. Can I prevent it?
Maybe it's connected with https://github.com/pytest-dev/pytest-django/issues/1054 but I am not sure.
By the way, I am using now in conftest.py to prevent using of django_db(transaction=True), but I am not sure that it will work stably. Like in this case.
@pytest.fixture(scope="session")
def celery_worker_parameters():
from celery.fixups.django import DjangoWorkerFixup
DjangoWorkerFixup.install = lambda x: None
# This needed, because there is error InterfaceError: connection already closed
# https://stackoverflow.com/questions/71472478/celery-worker-fixture-in-pytest-connection-already-closed-error
return {"without_heartbeat": False}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the parametrized test behavior with the celery_worker fixture and mailoutbox, then inspect the conftest.py celery_worker_parameters override shown in the report. Determine whether task completion and database connection handling are coordinated; done means delayed tasks reliably produce all expected mailoutbox messages without time.sleep(1).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100