gpt4 book ai didi

django - 如何测试自定义 django-admin 命令

转载 作者:行者123 更新时间:2023-11-28 19:34:12 26 4
gpt4 key购买 nike

我创建了 custom django-admin commands

但是,我不知道如何在 standard django tests 中测试它

最佳答案

如果您正在使用一些覆盖工具,最好从代码中调用它:

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.

From the official documentation

Management commands can be tested with the call_command() function. The output can be redirected into a StringIO instance

关于django - 如何测试自定义 django-admin 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1286700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com