【发布时间】:2020-05-12 13:41:08
【问题描述】:
我已经创建了名为 pytest_wrp 的自定义管理命令
所以当我打电话时
python manage.py test
这段代码叫做:
class Command(test.Command):
def handle(self, *args, **options):
super(Command, self).handle(*args, **options) # this calls the python manage.py test
self.stdout.write("My code starts from here.")
management.call_command(pytest_wrp.Command(), '--pact-files="{argument}"'.format(argument=path_to_file), '--pact-provider-name="MyService"', verbosity=0)
pytest_wrp 里面基本上有这个代码:
class Command(BaseCommand):
help = "Runs tests with Pytest"
def add_arguments(self, parser):
parser.add_argument("args", nargs=argparse.REMAINDER)
def handle(self, *args, **options):
pytest.main(list(args)) # This doesn't accept the pact args, even if you specify a "--" separator
但这调用pytest 而不是pytest-django
因此,我传递的额外参数无法识别,pytest 无法启动测试套件。
我想为一些测试用例传递额外的参数。 如果有某种方法可以直接调用 pytest-django 并在代码中传递额外的参数,那将是最佳的。
【问题讨论】:
标签: django django-admin pytest pytest-django django-management-command