3

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()

ただし、Django 1.8 では_commands存在しなくなりました。コードを見ると、これらは django.core.management.get_commands を介して動的に取得されるようになりましたが、任意のコマンド クラスを追加または登録する方法はありません。これは可能ですか?

4

0 に答える 0