简体   繁体   中英

Pytest not found in Azure DevOps Pipeline

In my Azure DevOps Pipeline

( https://dev.azure.com/TheNewThinkTank/dark-matter-attractor/_build?definitionId=2&_a=summary )

I have a test stage from where I wish to install and run pytest on all Python files in the corresponding Azure DevOps repository

( https://dev.azure.com/TheNewThinkTank/_git/dark-matter-attractor ).

The way Pytest is installed and run follows the official Microsoft documentation:

- script: |
    pip install pytest
    pip install pytest-cov
    pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
  displayName: 'Test with pytest'

Which can be found at: https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops

Running the Pipeline results in an error at the above step: pytest: command not found

If you wish to see the full traceback:

https://dev.azure.com/TheNewThinkTank/dark-matter-attractor/_build/results?buildId=62&view=logs&j=792982d5-3bb1-5d82-222e-228148b73448&t=1f7e9bd0-3cdf-5b91-30b0-87c9b2af71b7

Other things I have tried:

Following the official pytest site ( https://docs.pytest.org/en/stable/getting-started.html ), I tried adding a flag to the install command: pip install -U pytest , but with the same outcome.

What is preventing the Pipeline from discovering the installed pytest module?

Please try python -m pytest :

- script: |
    pip install pytest
    pip install pytest-cov
    python -m pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
  displayName: 'Test with pytest'

Modules installed over pip are not recognized as system level command.

@Krzysztof Madej, current directory is not loaded as PYTHONPATH, Therefore having module not found error

 /usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_cfn_params_handler.py:17: in <module>
    from manifest.cfn_params_handler import CFNParamsHandler
E   ModuleNotFoundError: No module named 'manifest'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM