我制作了名为 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 并在代码中传递额外的参数,那将是最佳的。