わたしは作ったカスタム django-admin コマンド
しかし、どうやってテストすればいいのか分からない標準の Django テスト
ベストアンサー1
カバレッジ ツールを使用している場合は、次のようにコードから呼び出すとよいでしょう。
from django.core.management import call_command
from django.test import TestCase
class CommandsTestCase(TestCase):
def test_mycommand(self):
" Test my custom command."
args = []
opts = {}
call_command('mycommand', *args, **opts)
# Some Asserts.
管理コマンドはcall_command()関数でテストできます。出力はStringIOインスタンスにリダイレクトできます。