0

I'm trying to run a python test in Azure DevOps and the only error I'm receiving is this:

==================================== ERRORS ====================================
_________________ ERROR collecting tests/unit/test_handler.py __________________
ImportError while importing test module '/home/vsts/work/1/s/tests/unit/test_handler.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/unit/test_handler.py:5: in <module>
    from hello_world import app
E   ModuleNotFoundError: No module named 'hello_world'
----------- generated xml file: /home/vsts/work/1/s/test-output.xml ------------

I'm really not sure why it's saying "No module named 'hello_world'"? Here is my YAML configuration for my pipeline, is this the issue?

trigger:
- main

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    Python37:
      python.version: '3.7'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip
    pip install -r hello_world/requirements.txt
  displayName: 'Install dependencies'

- script: |
    pip install pytest pytest-azurepipelines
    pytest
  displayName: 'pytest'
MP32
  • 573
  • 1
  • 9
  • 25

1 Answers1

0

In order to load hello_world as a module, you need to first make it installable and install it. You can do this by simply creating a setup.py file (see this thread for example), after which you can install your hellow_world package by pip install -e ., where -e means "editable" so that you do not need to reinstall every time you make any change to the source code in hellow_world.

Remy Lau
  • 142
  • 1
  • 4