pytest
Technical notes on web development, DevOps, and AI integration.
2 articles
- 23:25backend
Red Pipeline, Green Laptop: Migrations Before pytest
CI called pytest on an empty database while production applied migrations first; one workflow line aligned both contracts.
TL;DR: A test suite that passed locally kept failing in CI with misleading database errors. The root cause was that production ran Alembic migrations before boot, while CI pointed pytest straight at an empty Postgres. Adding alembic upgrade head before tests in the workflow made starting state deterministic, so failures now point at actual code.
#ci#alembic#pytest - 22:43backend
When EmailStr Rejects .test Fixtures Under Pydantic
email-validator rejects reserved test domains at the syntax layer; here is how to pick fixture domains that pass Pydantic validation.
TL;DR: CI failures on register and login endpoints came from Pydantic's EmailStr rejecting reserved domains like .test and .local at the syntax layer, before any DNS lookup. The simplest fix is swapping fixtures to example.com, example.net, or example.org, which pass validation. Alternatively, pass test_environment=True to email-validator, though Pydantic needs a custom wrapper for that.
#python#pydantic#email-validator