Skip to course content
Free generative AI app course

Generative AI Application Development with Python

Unit 02.04: A local setup someone else can reproduce

The test of a local setup is whether someone else can run the tests without a key.

Pinned, ignored, and runnable offline

Dependencies, environment variables, gitignore entries and the first command.

The code prints the setup and checks it.

import json

setup = {
    "python": "3.12+",
    "dependencies": "pinned in requirements.txt, including transitive pins",
    "environment": {"APP_API_KEY": "from the provider, never committed",
                    "APP_MODEL": "defaults to a fake for tests",
                    "APP_DAILY_USD": "0.50"},
    "run_tests_without_a_key": True,
    "first_command": "pytest -q   # must pass with no key set",
    "gitignored": [".env", "*.log", "__pycache__"],
}
print(json.dumps(setup, indent=2))

checks = [
    ("tests run with no API key", setup["run_tests_without_a_key"]),
    ("dependencies are pinned", "pinned" in setup["dependencies"]),
    (".env is ignored", ".env" in setup["gitignored"]),
    ("a fake model is the default", "fake" in setup["environment"]["APP_MODEL"]),
]
for check, ok in checks:
    print(f"  {'OK  ' if ok else 'FAIL'} {check}")

# The first check is the important one. If the test suite needs a key, nobody
# runs it -- and the parts most worth testing need no model at all.

The first check is the important one. If the test suite needs an API key, nobody runs it on every change - and the parts most worth testing need no model at all, which Module 11 makes concrete.

Pinning transitive dependencies matters more here than in most projects, because provider SDKs move quickly and a minor bump can change response shapes.

The mistake this prevents

The mistake is a setup that works on your machine because of environment you have forgotten about. Test it by cloning fresh into a new directory with no environment set and running the first command.

Takeaway

Pin dependencies, gitignore secrets, default to a fake model, and make the test suite pass with no key. Verify by cloning fresh.