Skip to content

[FAQ Contribution] How to fix PyTest "ModuleNotFoundError: No module named 'src'" on Linux #347

Description

@yazdanparasthesam

How do I fix ModuleNotFoundError: No module named 'src' when running pytest tests/ -v on Linux?

Problem:
When running automated tests on Linux (Ubuntu/Debian) with Python 3.10+, pytest fails with:
ModuleNotFoundError: No module named 'src' even though the src/ directory exists.

Why it happens:
Unlike some IDE environments, standard Linux pytest does not automatically add the project root directory (.) to the Python module search path (PYTHONPATH).

Solution:
There are two ways to permanently fix this:

  1. Create a pytest.ini file in your repository root:
    [pytest]
    pythonpath = .
    testpaths = tests

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