#Python

147 posts

Python Testing #4 mock and monkeypatch: Controlling What You Can't Control
7 min read

Python Testing #4 mock and monkeypatch: Controlling What You Can't Control

How to pin down dependencies that change on every run — time, randomness, external APIs — with monkeypatch and unittest.mock, including the patch-path trap and where over-mocking begins.

Python Testing #3 parametrize and Markers: Multiply Cases, Run Selectively
5 min read

Python Testing #3 parametrize and Markers: Multiply Cases, Run Selectively

How to collapse input-only test variations into one case table with @pytest.mark.parametrize, and run only the tests you want using skip, skipif, xfail, custom markers, and the -m and -k options.

Python Testing #2 Fixtures: Injecting Setup and Teardown
6 min read

Python Testing #2 Fixtures: Injecting Setup and Teardown

How to inject test setup code with @pytest.fixture — yield teardown, scope trade-offs, sharing via conftest.py, and built-in fixtures like tmp_path.

Python Testing #1 Getting Started with pytest: Why One assert Is All You Need
7 min read

Python Testing #1 Getting Started with pytest: Why One assert Is All You Need

How to install pytest and write your first test with a single assert — plus how it differs from unittest, how to read failure output, and the test discovery rules.

Modern Python in Practice #6: Testing and Deployment — pytest, Docker, Railway/Fly
9 min read

Modern Python in Practice #6: Testing and Deployment — pytest, Docker, Railway/Fly

FastAPI integration tests with pytest + httpx, isolation via dependency overrides, multi-stage Docker builds, and cloud deployment to Railway/Fly.

Modern Python in Practice #5: Async and Background Tasks
7 min read

Modern Python in Practice #5: Async and Background Tasks

Where async routes fit, post-response processing with BackgroundTasks, the boundary where external queues (Celery, ARQ) become necessary, and how to safely mix sync libraries.

Modern Python in Practice #4: Authentication — OAuth2 Password Flow + JWT
8 min read

Modern Python in Practice #4: Authentication — OAuth2 Password Flow + JWT

Password hashing (argon2/bcrypt), the OAuth2 password flow, JWT issuance/verification, and a clean current_user dependency for authenticated routes.

Modern Python in Practice #3: Connecting a DB — SQLAlchemy 2.x + Alembic
8 min read

Modern Python in Practice #3: Connecting a DB — SQLAlchemy 2.x + Alembic

SQLAlchemy 2.x's new style — Mapped/mapped_column, async sessions, integration with FastAPI's dependency injection, and Alembic migrations.

Modern Python in Practice #2: Routing, Pydantic Models, and Dependency Injection
7 min read

Modern Python in Practice #2: Routing, Pydantic Models, and Dependency Injection

Splitting routes with APIRouter, defining input/output schemas with Pydantic v2, and unraveling shared logic cleanly with Depends.

Modern Python FastAPI #1 Getting Started and Setup
7 min read

Modern Python FastAPI #1 Getting Started and Setup

Why FastAPI, first project setup with uv, Hello FastAPI, automatic OpenAPI/Swagger UI generation — all in one place.

Modern Python Advanced #7 Performance — cProfile, py-spy, Memory Profiling
8 min read

Modern Python Advanced #7 Performance — cProfile, py-spy, Memory Profiling

A toolbox for finding and fixing slow Python code — timeit, cProfile, py-spy, line_profiler, memray, and common optimization patterns.

Modern Python Advanced #6: Advanced typing — Variance, ParamSpec, Self, overload
4 min read

Modern Python Advanced #6: Advanced typing — Variance, ParamSpec, Self, overload

Next step from intermediate typing — covariance/contravariance, ParamSpec and Concatenate, Self, TypeGuard/TypeIs, and @overload.