Skip to content

ModuleNotFoundError: No module named. In github actions by using pytest #12984

Closed as not planned
@danilyef

Description

I have the following structure in github repository:

homework_6/
├── pr3/
│   ├── project/
│   │   ├── __init__.py
│   │   ├── main.py
│   │   ├── model.py
│   │   └── processing.py
│   ├── report_model.html
│   └── tests/
│       ├── __init__.py
│       └── model/
│           ├── __init__.py
│           └── test_model.py

homework_9/
├── pr1/
│   ├── README.md
│   ├── project/
│   │   ├── __init__.py
│   │   ├── main.py
│   │   └── utils.py
│   ├── requirements.txt
│   └── tests/
│       ├── __init__.py
│       └── model/
│           ├── __init__.py
│           └── test_streamlit.py
└── pr2/
    ├── README.md
    ├── project/
    │   ├── __init__.py
    │   ├── main.py
    │   └── utils.py
    ├── requirements.txt
    └── tests/
        ├── __init__.py
        └── model/
            ├── __init__.py
            └── test_gradio.py

When I run test by using github actions, all the tests from homework_6 are collected and work without errors, but when the tests from homework_9 fail with the following error messages:

ERROR collecting homework_9/pr1/tests/model/test_streamlit.py _________
  ImportError while importing test module '/home/runner/work/machine_learning_in_production/machine_learning_in_production/homework_9/pr1/tests/model/test_streamlit.py'.
  Hint: make sure your test modules/packages have valid Python names.
  Traceback:
  /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/importlib/__init__.py:126: in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
  E   ModuleNotFoundError: No module named 'tests.model.test_streamlit'

And I don't understand why (especially when tests from homework_6 run without problem).

Here is my github action file:

    name: ci
    
    on:
      push: 
      pull_request:
    
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v4
        - name: Set up Python
          uses: actions/setup-python@v5
          with:
            python-version: '3.11'
        - name: Install dependencies
          run: |
            python -m pip install --upgrade pip
            pip install -r main_requirements.txt
        - name: Run tests
          run: pytest -v --tb=long

And locally everything works without any error.

pytest version: 8.3.0

Metadata

Assignees

No one assigned

    Labels

    stalestatus: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivitytopic: collectionrelated to the collection phasetype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions