Skip to main content

pytest plugin providing a function to check if pytest is running.

Project description

https://img.shields.io/github/actions/workflow/status/adamchainz/pytest-is-running/main.yml?branch=main&style=for-the-badge https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge https://img.shields.io/pypi/v/pytest-is-running.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

pytest plugin providing a function to check if pytest is running.

Unmaintained (2024-01-02)

I stopped maintaining this package as it doesn’t provide much value over checking whether pytest has been imported:

import sys

if "pytest" in sys.modules:
    ...

In every project I’ve seen, pytest is only imported when running.


Working on a Django project? Check out my book Boost Your Django DX which covers many ways to improve your development experience. I created pytest-is-running whilst working on the book!


Installation

Install with:

python -m pip install pytest-is-running

Python 3.8 to 3.12 supported.

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.

Upstream issue #9502 discusses adding a feature to pytest. It also covers an alternative which is often “good enough” - a simple check if pytest has been imported with:

"pytest" in sys.modules

This won’t be strictly accurate if you happen to import pytest outside of your test run, but that is not very common. You may prefer to using this simpler technique instead of this plugin.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-is-running-1.5.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

pytest_is_running-1.5.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-is-running-1.5.1.tar.gz.

File metadata

  • Download URL: pytest-is-running-1.5.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytest-is-running-1.5.1.tar.gz
Algorithm Hash digest
SHA256 885cc87e5e3874d80f1f4610967c20430c2c169b2b2e6227da43a7b80dbe8a73
MD5 e3df98c30a7f7aa2f2f8c2ba19e86fcd
BLAKE2b-256 464da7c4a16f74661bed99607182f6f87844ab84dab89579aaf4f296318f8097

See more details on using hashes here.

File details

Details for the file pytest_is_running-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_is_running-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d08ef02b59b67df57bd4766ba8e4a715a867e03e4b7abc193f14dff5666c2a3f
MD5 ac8908530342105cee6b49d7b1ec7719
BLAKE2b-256 544555a7d7ef1a908d92cb01ecdad5f6e10f941b972087c4dd0cd16fc27f5b5f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page