1
votes

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://docs.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?

2

2 Answers

2
votes

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.

0
votes

@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'