0

Consider the following (simple) project structure :

taxidriver
|-- src
|  |-- __init__.py
|  |-- libtaxi.py
|  |-- libformat.py
|  |-- app.py
|-- tests
   |-- __init__.py
   |-- test_taxi.py
   |-- test_format.py
   |-- test_integration.py

My issue is related to pytest always sending ImportError while importing test module $Rightarrow$ ModuleNotFoundError: No module named 'src.libtaxi'.

  • In the libformat.py I call the imports like so :
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from rich.table import Table
from rich.markdown import Markdown
from src import libtaxi as lt
  • In the app.py I call the imports like so :
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import typer
from taxidriver import libtaxi as lt
from taxidriver import libformat as lf

  • The imports inside the tests folder from file test_format :
from src.libtaxi import (
    Emplacement,
    Itineraire,
    Ville,
)
from src.libformat import format_emplacement, format_routes, format_trajet

Note that relative imports yields the same results as absolute imports and sends back an import module Error. Is there an issue with my imports ?

Smorg
  • 55
  • 4
  • I think you have to set `PYTHONPATH`. See [this post](https://stackoverflow.com/questions/43728431/relative-imports-modulenotfounderror-no-module-named-x) – frankfalse May 05 '23 at 09:00

0 Answers0