Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
pytest documentation
Logo
  • Get Started
  • How-to guides
    • How to invoke pytest
    • How to write and report assertions in tests
    • How to use fixtures
    • How to mark test functions with attributes
    • How to parametrize fixtures and test functions
    • How to use subtests
    • How to use temporary directories and files in tests
    • How to monkeypatch/mock modules and environments
    • How to run doctests
    • How to re-run failed tests and maintain state between test runs
    • How to handle test failures
    • Managing pytest’s output
    • How to manage logging
    • How to capture stdout/stderr output
    • How to capture warnings
    • How to use skip and xfail to deal with tests that cannot succeed
    • How to install and use plugins
    • Writing plugins
    • Writing hook functions
    • How to use pytest with an existing test suite
    • How to useunittest-based tests with pytest
    • How to implement xunit-style set-up
    • How to set up bash completion
  • Reference guides
    • API Reference
    • Fixtures reference
    • Configuration
    • Exit codes
    • Pytest Plugin List
  • Explanation
    • Anatomy of a test
    • About fixtures
    • Good Integration Practices
    • pytest import mechanisms andsys.path/PYTHONPATH
    • Typing in pytest
    • CI Pipelines
    • Flaky tests
  • Examples and customization tricks
    • Demo of Python failure reports with pytest
    • Basic patterns and examples
    • Parametrizing tests
    • Working with custom markers
    • A session-fixture which can look at all collected tests
    • Changing standard (Python) test discovery
    • Working with non-python tests
    • Using a custom directory collector

About the project

  • Changelog
  • Contributing
  • Backwards Compatibility Policy
  • History
  • Python version support
  • Sponsor
  • pytest for enterprise
  • License
  • Contact channels

Useful links

  • pytest @ PyPI
  • pytest @ GitHub
  • Issue Tracker
  • PDF Documentation
Back to top

Next Open Trainings and Events

  • Professional Testing with Python, viaPython Academy (3 day in-depth training),March 3th – 5th 2026, Leipzig (DE) / Remote

Also seeprevious talks and blogposts

pytest: helps you write better programs¶

Thepytest framework makes it easy to write small, readable tests, and canscale to support complex functional testing for applications and libraries.

PyPI package name:pytest

A quick example¶

# content of test_sample.pydefinc(x):returnx+1deftest_answer():assertinc(3)==5

To execute it:

$ pytest=========================== test session starts ============================platform linux -- Python 3.x.y, pytest-9.x.y, pluggy-1.x.yrootdir: /home/sweet/projectcollected 1 itemtest_sample.pyF[100%]================================= FAILURES =================================_______________________________ test_answer ________________________________    def test_answer():>       assert inc(3) == 5E       assert 4 == 5E        +  where 4 = inc(3)test_sample.py:6: AssertionError========================= short test summary info ==========================FAILED test_sample.py::test_answer - assert 4 == 5============================1 failed in 0.12s =============================

Due topytest’s detailed assertion introspection, only plainassert statements are used.SeeGet started for a basic introduction to using pytest.

Features¶

  • Detailed info on failingassert statements (no need to rememberself.assert* names)

  • Auto-discovery of test modules and functions

  • Modular fixtures for managing small or parametrized long-lived test resources

  • Can rununittest (including trial) test suites out of the box

  • Python 3.10+ or PyPy 3

  • Rich plugin architecture, with over 1300+external plugins and thriving community

Documentation¶

  • Get started - install pytest and grasp its basics in just twenty minutes

  • How-to guides - step-by-step guides, covering a vast range of use-cases and needs

  • Reference guides - includes the complete pytest API reference, lists of plugins and more

  • Explanation - background, discussion of key topics, answers to higher-level questions

Bugs/Requests¶

Please use theGitHub issue tracker to submit bugs or request features.

Support pytest¶

Open Collective is an online funding platform for open and transparent communities.It provides tools to raise money and share your finances in full transparency.

It is the platform of choice for individuals and companies that want to make one-time ormonthly donations directly to the project.

See more details in thepytest collective.

pytest for enterprise¶

Available as part of the Tidelift Subscription.

The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support andmaintenance for the open source dependencies you use to build your applications.Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.

Learn more.

Security¶

pytest has never been associated with a security vulnerability, but in any case, to report asecurity vulnerability please use theTidelift security contact.Tidelift will coordinate the fix and disclosure.

Next
Get Started
Copyright © 2015, holger krekel and pytest-dev team
Made withSphinx and@pradyunsg'sFuro
On this page
  • pytest: helps you write better programs
    • A quick example
    • Features
    • Documentation
    • Bugs/Requests
    • Support pytest
    • pytest for enterprise
      • Security

[8]ページ先頭

©2009-2026 Movatter.jp