您可以将 Celery runner 和 Nose runner 子类化,然后您将获得所有这些方面的好处。
from django_nose import NoseTestSuiteRunner
from djcelery.contrib.test_runner import CeleryTestSuiteRunner
class TestRunner(CeleryTestSuiteRunner, NoseTestSuiteRunner):
pass
然后在您的设置中:
TEST_RUNNER = '<package to>.TestRunner'
为什么有效:
help(TestRunner)
你得到:
| Method resolution order:
| TestRunner
| djcelery.contrib.test_runner.CeleryTestSuiteRunner
| django_nose.runner.NoseTestSuiteRunner
| django_nose.runner.BasicNoseRunner
| django_nose.runner.BaseRunner
| django.test.runner.DiscoverRunner
| builtins.object
测试 CeleryTestRunner 只是设置一些配置然后调用super().setup_test_environment()
. 然后超级将在该链中寻找 setup_test_environment() 。
观看 Raymond Hettinger 的视频:超级被认为是超级(这里)。