Pytest recursively scans directories for test files It imports each file to discover test functions and classes It collects test metadata and applies filtering Only then can actual test execution begin $ docker compose run --rm tests pytest --postgresql-host db --collect-only # Before optimization: # 3,900+ tests collected in 7.84s # After optimization: # 3,900+ tests collected in 2.60s Figure 7: Computing the test collection time. During test initialization, each parallel test worker must execute these migrations to establish a clean test database.