Pregunta

I'm trying to test some celery functionality in my Django app, but I can't even get the basic testing system down.

When I follow what everything says and add TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner' to the bottom of my settings file, some unusual things happen when I try to test with manage.py test:

1) A bunch of tests I never wrote seem to be run. Previously, I had 18 tests that all passed. Now, I run the tests and I get this:

................................................................................
.....................x..........................................................
...................................................................
----------------------------------------------------------------------
Ran 227 tests in 0.802s

OK (expected failures=1)
Destroying test database for alias 'default'...

2) My tests have currently been in a folder named tests within my app folder, with each file named, e.g., test_models.py. However, upon adding the CelerySuiteTestRunner, none of those tests run at all - I can add failing tests and they don't fail.

3) However, if I get rid of that folder and add a single tests.py file in the app folder, anything in that file will run. (If I leave the tests folder in place, it will not run tests in the tests.py file.)

I'm just trying to add testing of my celery-related tasks to my app. Can anybody explain what is going on here?

Thanks!

¿Fue útil?

Solución

I assume you are using Django 1.6, which changed the default test runner. CeleryTestSuiteRunner inherits from Django's old DjangoTestSuiteRunner, which runs tests from all installed apps, including the apps provided with Django, but does not discover tests outside of the tests modules.

You could reimplement CeleryTestSuiteRunner in your own test runner using the new DiscoverRunner which will discover your tests as expected, e.g.:

from django.test.runner import DiscoverRunner
from djcelery.contrib.test_runner import _set_eager

class CeleryDiscoverRunner(DiscoverRunner):
    def setup_test_environment(self, **kwargs):
        _set_eager()
        super(CeleryDiscoverRunner, self).setup_test_environment(**kwargs)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top