Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsApr 12, 2026·2 min de lectura

pytest — The Python Testing Framework That Scales

pytest makes it easy to write small tests, yet scales to support complex functional testing. Fixtures, parameterization, plugins, markers, and a rich assertion introspection system. The de facto testing standard for the Python ecosystem.

Introducción

pytest is the de facto testing framework for Python. Simple enough for small tests, powerful enough for complex functional testing. Features include fixtures (dependency injection), parametrization, markers, plugins, and an incredibly helpful assertion introspection system that shows you exactly what failed and why.

What pytest Does

  • Auto-discovery — finds test_*.py files and test_* functions
  • Assertion introspection — plain assert with detailed failure diffs
  • Fixtures — DI for test setup/teardown (function, class, module, session scope)
  • Parametrize — run same test with multiple inputs
  • Markers@pytest.mark.slow, @pytest.mark.skip, custom
  • Plugins — 1200+ on PyPI (pytest-cov, pytest-xdist, pytest-mock, pytest-asyncio)
  • Conftest — shared fixtures across test directories
  • Temporary directoriestmp_path fixture
  • Capture — stdout/stderr capture per test
  • Parallel — via pytest-xdist

Comparison

Framework Style Fixtures Plugins
pytest Function-based DI (fixtures) 1200+
unittest Class-based setUp/tearDown Limited
nose2 Mixed Limited Some
doctest Inline None None

FAQ

Q: pytest vs unittest? A: pytest is more concise (no class needed), with better assertions (no assertEqual) and a stronger fixture DI. The vast majority of new Python projects use pytest.

Q: How to test async code? A: pip install pytest-asyncio, then use @pytest.mark.asyncio async def test_xxx() to await async functions.

Q: Fixture scope? A: function (once per test), class, module, session (once for the entire test run). Larger scope means lower setup overhead but weaker isolation.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados