Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments are not quoted when calling pytest #415

Open
jiasli opened this issue Jul 27, 2023 · 0 comments
Open

Arguments are not quoted when calling pytest #415

jiasli opened this issue Jul 27, 2023 · 0 comments

Comments

@jiasli
Copy link
Member

jiasli commented Jul 27, 2023

This issue is discovered while investigating Azure/azure-cli#27016

In the below example, '%(levelname)s %(name)s %(thread)d %(threadName)s %(message)s' is not quoted when being passed to pytest:

> azdev test test_keyvault_certificate_soft_delete --debug --pytest-args --log-level=DEBUG --log-format '%(levelname)s %(name)s %(thread)d %(threadName)s %(message)s'

cli.azdev.operations.testtool.pytest_runner: Running: python -m pytest -x -v -p no:warnings --log-level=WARN --junit-xml C:\Users\xxx\.azdev\env_config\cli\py310\test_results.xml d:\cli\azure-cli\src\azure-cli\azure\cli\command_modules\keyvault\tests\latest\test_keyvault_commands.py::KeyVaultCertificateRestoreScenarioTest::test_keyvault_certificate_soft_delete -n auto --log-level=DEBUG --log-format %(levelname)s %(name)s %(thread)d %(threadName)s %(message)s

This is because arguments with spaces are not quoted when constructing the command string:

cmd = 'python -m pytest {}'.format(' '.join(arguments))

Even though shlex.quote can be used to quote arguments, the recommended approach for calling subprocess.call is "providing a sequence of arguments": https://docs.python.org/3/library/subprocess.html#frequently-used-arguments.

Also see: Azure/cli#105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant