# pyproject.toml
[tool.pytest.ini_options]
addopts = [
    "--import-mode=importlib",
]
pythonpath = [
  "."
]

In test files, use relative imports as absolute imports will raise an exception:

# tests/test_main.py
from ..app import main
from ..app.tdp_client import InMemoryApiClient

Same for the code under test: only relative imports will work.

  • q How to improve this? I can’t use absolute imports.