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

mailoutbox doesn't work correctly with celery_worker

Open mihalt opened this issue 2 years ago • 0 comments

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}

mihalt avatar Apr 01 '23 13:04 mihalt