如何在Django unittes中注册自定义管理命令

2024-09-30 00:34:47 发布

您现在位置:Python中文网/ 问答频道 /正文

如何注册仅存在于unittest中的自定义Django管理命令?你知道吗

在Django 1.5中,您可以这样做:

from django.test import TestCase
from django.core.management import _commands

from myapp.testse.commands import MyTestCommand

class JobTestCase(TestCase):

    fixtures = ['test_jobs.json']

    def setUp(self):
        # Install the test command; this little trick installs the command
        # so that we can refer to it by name
        _commands['test_command'] = MyTestCommand()

但是,在django1.8中,_commands不再存在。从代码中看,现在似乎可以通过django.core.management公司.getu命令,但我没有看到添加或注册任意命令类的方法。这可能吗?你知道吗


Tags: thedjangofromcoretestimport命令unittest

热门问题