pytest-custom-exit-code

0.3.0 · maintenance · verified Thu Apr 09

pytest-custom-exit-code is a pytest plugin that allows users to customize the exit code of a pytest test session in specific scenarios. Currently at version 0.3.0, its primary function is to alter the default exit codes, such as when no tests are collected or when tests fail. The library has had a slow release cadence, with the last update in August 2019.

Warnings

Install

Quickstart

The plugin is typically used by passing command-line options to `pytest` or by configuring them in a `pytest.ini` file. There are no direct Python imports from the plugin itself for its core functionality. The primary options are `--suppress-no-test-exit-code` to change exit code 5 (no tests collected) to 0, and `--suppress-tests-failed-exit-code` to change exit code 1 (tests failed) to 0.

# To install the plugin
pip install pytest-custom-exit-code

# --- Example: pytest.ini configuration to suppress 'no tests collected' exit code ---
# Create a pytest.ini file in your project root with the following content:
# [pytest]
# addopts = --suppress-no-test-exit-code

# To demonstrate, create an empty test file (e.g., test_nothing.py)
# Then run pytest:
# pytest test_nothing.py
# This would normally exit with code 5 (no tests collected). With the plugin and config,
# it will exit with code 0. If you delete the pytest.ini or remove the addopt, it will revert.

# --- Example: Using command-line options directly ---
# Suppress exit code when no tests are collected:
# pytest --suppress-no-test-exit-code

# Suppress exit code when tests fail:
# pytest --suppress-tests-failed-exit-code

view raw JSON →