Python guides
Every published Python guide, newest first, with practical examples you can copy into your own project.
3,965 guides across 14 topics
Topics
Popular Python guides
Most readLatest Python guides
Page 20 of 179Python pytest setup/teardown vs fixtures: Which should you use?
Python pytest setup/teardown vs fixtures: Compare xunit-style setup/teardown methods with pytest fixtures to decide which approach improves test isolation, sharing, and maintainability.
pytest Fixtures: monkeypatch, tmp_path, caplog, and capsys
Learn how pytest's built-in monkeypatch, tmp_path, caplog, and capsys fixtures isolate tests, with examples for environment variables, files, logs, and stdout/stderr.
Python Pytest Exception Testing with pytest.raises
Use pytest.raises to assert exception types and messages in Python: inspect raised exceptions, parametrize test cases, and avoid common mistakes.
Python pytest marks: skip, skipif, and xfail
Use pytest's skip, skipif, and xfail markers to control test execution: skip a test unconditionally, skip when a condition is true, or mark a failing test as expected.
Using pytest.mark.parametrize for Parameterized Tests in Python
Learn how to use pytest.mark.parametrize to write parameterized tests in Python. Covers syntax, multiple arguments, fixtures, custom IDs, class/module-level use, and common pitfalls.
Python Pytest Fixtures Scope and conftest
Learn how pytest fixture scope controls setup frequency and how conftest.py shares fixtures across test files, including when widening scope is safe.
Python Pytest: Basic Tests, Assertions, and Test Discovery
Learn how to write basic pytest tests with plain assert statements, understand pytest test discovery rules, test exceptions and floating-point values, and run a subset of tests.
Python Celery vs APScheduler: Choosing the Right Task Scheduler
Compare Celery and APScheduler for Python background tasks: architecture, scheduling, reliability, scaling, and when to choose each.
Using Python Celery with FastAPI and Django
Integrate Celery with FastAPI and Django: configure a shared Celery app, define reusable tasks, call tasks from views and endpoints, and handle results, errors, and monitoring.
Python Celery Rate Limits: Syntax and Worker Behavior
Configure Python Celery rate limits on tasks, read the rate-limit string syntax, and understand how each worker instance enforces limits.