Skip to main content

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

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

https://img.shields.io/github/workflow/status/adamchainz/pytest-is-running/CI/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.

Installation

Install with:

python -m pip install pytest-is-running

Python 3.7 to 3.11 supported.


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!


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.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_is_running-1.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest-is-running-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a7cf503cf9d6c16b4e1872f9c45ebb27cfc974b540ac97dbfce6f2a36811b914
MD5 b3deddd7a2431471da3691d790694c2a
BLAKE2b-256 30b052cf69b7855c28742e8d052f321f22ed3c0a8a9561af27d39d8fb9a00f4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_is_running-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ba1a26342be6581381047aa9a89bf60f8bd466e8992443d1bb80cbdd61a3329
MD5 38242e3d000d49e37836d3a012fda54c
BLAKE2b-256 7419215fbd4dd4bb9a72573ad1cc4b09214b639c431717e8d8d66f6d4c4d1515

See more details on using hashes here.

Supported by

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