0
votes

my tests work fine when my target is a single function (see 'Target' field in the image):

questionator.test_mturk_views.TestReport.submit

However, when I specify my target to include all tests within my questionator app:

questionator

I get this error:

Error ImportError: Failed to import test module: src.questionator.test_mturk_views Traceback (most recent call last):
File "C:\Python27\Lib\unittest\loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "C:\Python27\Lib\unittest\loader.py", line 232, in _get_module_from_name import(name) File "C:\Users\Andy\questionator_app\src__init__.py", line 5, in from .celery import app as celery_app # noqa ImportError: No module named celery

Note that my tests include my settings via 'Environment variables' (see this in the pic too):

DJANGO_SETTINGS_MODULE=questionator_app.settings.development;PYTHONUNBUFFERED=1

The celery documentation mentions a "Using a custom test runner to test with celery" but this is in the now defunct djcelery package. I did though copy/paste/tweak this mentioned test runner and used it as described, but I get the same error.

Unfortunately using CELERY_ALWAYS_EAGER also does not work http://docs.celeryproject.org/en/latest/configuration.html#celery-always-eager

I would appreciate some guidance. With best wishes, Andy.

enter image description here

1
depending on the order the tests are run, and the order of your settings, a test might be trying to load the celery modules before it's available. Usually tests are run in alphabetical order, so make sure anything that runs before .test_mturk_views. would be able to load the Celery stuff. - blakev

1 Answers

0
votes

with-the-same-problem (most likely me),

I had followed the official tutorial for getting celery working in my project. They advised the below: enter image description here

Just making the last import explicit solved my problem:

from taskapp.celery import app as celery_app  # noqa

I'll see if I can nudge Celery's creators to update their tutorial (pull request).