Skip to content

Arguments are not quoted when calling pytest #415

@jiasli

Description

@jiasli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions