How to test uwsgi cron tasks

Hi everyone!

I am happy to be part of this forum. I would like to ask some may be a bit newbie question.
How I can unit test uwsgi task defined this way:

@cron(-1, -1, -1, -1, -1, target='spooler')
def send_mail(signum):
    """Send email every minute if any."""

    from import call_command

This cron is executed only when uwsgi is running.
On the other hand, coverage shows me that this line
is missed, i.e. not tested.

How I can test this code/line ?

I’m not sure how you’d test the cron behavior itself, but to test the code in the function, I think I would try to call it directly. I’d probably mock out the call_command because that would run a lot of code.

Something like (assuming a pytest-style test function):

from unittest import mock

from mymodule import send_mail

def test_send_email_cront(mock_call_command):

1 Like