PYTHON Contents

Project Structure Conventions (src/, tests/)

Use a predictable project layout to make imports reliable, tests discoverable, and production packaging straightforward.

On this page

Why Structure Matters

A consistent layout reduces import issues, improves test discovery, and makes packaging/deployment more predictable.

Common Layout

repo/
  src/
    myapp/
      __init__.py
      service.py
  tests/
    test_service.py
  pyproject.toml
  README.md

Operational Checklist

  • Keep app code under src/ to avoid accidental imports from the repo root.
  • Keep tests in a dedicated tests/ directory with clear naming.
  • Separate "app" modules from "infra" modules (I/O, clients, adapters).

Failure Modes

  • Import confusion: code works locally but fails in CI/prod due to path differences.
  • Test invisibility: inconsistent naming breaks discovery and coverage metrics.