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/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.

Installation

Install with:

python -m pip install pytest-is-running

Python 3.8 to 3.12 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.5.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.5.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_is_running-1.5.0.tar.gz.

File metadata

  • Download URL: pytest_is_running-1.5.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pytest_is_running-1.5.0.tar.gz
Algorithm Hash digest
SHA256 dc227f6d33f76c003c2e5b408734fb2cae02dbd627a1018f78d6196a796943e2
MD5 1431188c2325fb4b0dc10c89b6b0fe75
BLAKE2b-256 b82d797d2e84cb2bc1c1f6ef38833e81b9ea67a33c8cf69f2649aaffc8d7bfe9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_is_running-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bba7f7f4343bf8fbd5eb7ebb895ab21083b2779b89475211deba2d9bfa40f49
MD5 8aeef254921605dca1dae842406d3918
BLAKE2b-256 5bb58108380fc58373ffe1f2596349795868f2c23614bc6ceae4cf5bcd4280be

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