从昨天开始就关注这个。帮助! 我通过 pytest 中的命令行接收测试参数,如下所示。 我有一个 conftest.py 文件如下:
def pytest_addoption(parser):
parser.addoption('--client_id')
parser.addoption('--client_secret')
parser.addoption('--tenant_id')
parser.addoption('--rg_name')
parser.addoption('--dbhost')
parser.addoption('--dbtoken')
def pytest_generate_tests(metafunc):
os.environ['client_id'] = metafunc.config.getoption('client_id')
os.environ['client_secret'] = metafunc.config.getoption('client_secret')
os.environ['tenant_id'] = metafunc.config.getoption('tenant_id')
os.environ['rg_name'] = metafunc.config.getoption('rg_name')
os.environ['dbhost'] = metafunc.config.getoption('dbhost')
os.environ['dbtoken'] = metafunc.config.getoption('dbtoken')
示例测试如下:
def test_my_app():
assert get_run_status() =='Succeeded'
当我通过命令或 VSCode 终端在本地机器上调用我的测试并提供参数时,一切正常。但是当我在 Azure Devops yaml 中执行相同的调用时,出现错误:
__main__.py: error: unrecognized arguments: --client_id *** --client_secret *** --tenant_id *** --rg_name *** --dbhost *** --dbtoken eooE0aU_-k383Aihz.cddvvnNJH_XP27-ya14pFgsYaLxB2yXhXre4
上面给出的令牌是运行日志中返回内容的缩短“修改”版本。
下面是 Azure Devops CI yaml
task: AzureCLI@2
inputs:
azureSubscription: 'subc-001'
scriptType: 'bash'
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
python -m pytest -rA ./test_folder/ --client_id $(xClientId) --client_secret $(xClientSecret) --tenant_id $(xtenantId) --rg_name $(xRg) --dbhost $(xDBhost) --dbtoken $(xToken) --doctest-modules --junitxml=test-results.xml
workingDirectory: '$(Pipeline.Workspace)/data/Tests/'
displayName: Run tests
当我在命令或 vscode 终端中按如下方式调用测试时,它工作正常! :
pytest -rA ./test_folder/ --client_id xxxxxxx --client_secret xxxxx --tenant_id xxxxx --rg_name xxxxx --dbhost xxxxx --dbtoken xxxxx
我在 yaml 中做错了什么?