pytest-is-running
pytest plugin providing a function to check if pytest is running.
Installation
Install with:
python -m pip install pytest-is-running
Python 3.6 to 3.10 supported.
Testing a Django project? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.
Usage
pytest will automatically find the plugin and use it when you run pytest
. You can check if pytest is running with the is_running()
function:
import pytest_is_running
if pytest_is_running.is_running():
...
The package avoids importing pytest if it is not running, so that you don’t incur that overhead in non-test paths.
The package registers its plugin hooks as early as possible in pytest’s process, so it should be loaded before any of your non-test modules.
Rationale
This plugin is an alternative to re-implementing the pattern in the Pytest documentation. As a plugin, it is loaded earlier than conftest.py
or any other code in your project. This makes it a more robust way of checking whether Pytest is currently running.