pytest
Dev ToolsThe pytest framework makes it easy to write small tests, yet scales to support complex functional testing
Release History
9.0.24 fixes1 featurepytest 9.0.2 fixes several bugs, restores a broken private config attribute, updates documentation, and disables the terminal progress plugin by default for better terminal compatibility.
9.0.14 fixespytest 9.0.1 is a bug‑fix release that restores unittest.SkipTest support, disables the terminal progress plugin on iTerm2, corrects API reference types, and resolves a UserWarning on early Python 3.12/3.13 builds.
9.0.06 fixes8 featurespytest 9.0.0 adds experimental subtests, native TOML config, a global strict mode, terminal progress reporting, and several new configuration options while improving performance and error messages.
8.4.25 fixespytest 8.4.2 fixes several crashes (including console output style, decimal handling, and NumPy imports) and improves Python 3.14 compatibility.
8.4.13 fixespytest 8.4.1 fixes several bugs including TerminalReporter.isatty handling, restores the PytestReturnNotNoneWarning, and adds compatibility with Twisted 25+.
8.4.0Breaking10 featurespytest 8.4.0 introduces significant breaking changes—removing Python 3.8 support, enforcing stricter test return values, and disallowing yield tests—while adding powerful new features like RaisesGroup, enhanced xfail handling, and configurable output options.
8.3.55 fixes1 featurepytest 8.3.5 delivers multiple bug fixes—including import‑mode crashes and libedit input handling—and re‑enables support for newer Towncrier versions when building Sphinx documentation.
Common Errors
ZeroDivisionError6 reportsA ZeroDivisionError in pytest usually arises from dividing by zero during a test, often within custom test logic or fixtures. To fix it, carefully inspect the traceback to pinpoint the faulty calculation and ensure the denominator is never zero by adding conditional checks or using appropriate error handling techniques to prevent the division. Provide a default value or use `pytest.skip` if a zero denominator renders the test meaningless.
ModuleNotFoundError3 reportsThe "ModuleNotFoundError" in pytest usually indicates that a required Python package or module isn't installed or isn't in the Python path being used by pytest. To fix this, ensure that all necessary packages are installed, ideally using `pip install <package_name>`, and verify that your PYTHONPATH environment variable or pytest configuration correctly points to the location of the missing module if it's a custom one. You may need to activate the correct virtual environment if the module is installed there.
AssertionError3 reportsAssertionError in pytest usually indicates that a test's expected outcome doesn't match the actual result, signifying a failed assertion. To fix it, carefully examine the traceback to identify the specific assertion that failed and then adjust either the expected value or the code under test to ensure they align, or alternatively use `pytest.approx` to allow for small numerical differences. Debugging the test or the tested function is crucial to pinpoint the root cause of the discrepancy.
UncaughtCharmError1 reportThe "UncaughtCharmError" in pytest, often occurring in pdb or traceback displays, typically arises from incorrect handling of terminal size or encoding changes during exception processing. To fix this, ensure that the `CHARM_DEBUG` environment variable is not set (or is set to an empty string) and that pytest's terminal output configurations are compatible with the execution environment; try running pytest with the `--no-header` flag to simplify terminal interactions.
AttributeError1 reportThis error usually arises when accessing a non-existent attribute or method of an object within your pytest code (e.g., trying to read a nonexistent option added via pytest_addoption). Inspect the traceback to identify the problematic attribute and object. Ensure the attribute is correctly defined on the object or that the method is available; double-check for typos and correct option names passed to pytest_addoption.
UnicodeEncodeError1 reportUnicodeEncodeError in pytest often arises when the test output (including captured stdout/stderr, or parametrization values) contains characters that cannot be encoded using the default terminal encoding (like ASCII). Force pytest to use UTF-8 encoding by setting the `PYTHONIOENCODING=utf-8` environment variable before running pytest, or configure your system to use UTF-8 as the default encoding to ensure consistent encoding across environments.
Related Dev Tools Packages
Empowering everyone to build reliable and efficient software.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Next generation frontend tooling. It's fast!
An extremely fast Python package and project manager, written in Rust.
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Subscribe to Updates
Get notified when new versions are released