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.3.0.tar.gz (4.4 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.3.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-is-running-1.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pytest-is-running-1.3.0.tar.gz
Algorithm Hash digest
SHA256 27792ca5edf853180fd365ed08754fcde6a787bc5b451379e02015ca7b2afee6
MD5 0f3c6be236009016c1c993c505adbf46
BLAKE2b-256 2fc7c58e13b16cf23e7df4160a9e5cf70831c3b9704bdd6dad2e0d686cb27f7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_is_running-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66f52837d7263756a603f4cc4cd13e8e93890fcbc3ec7ff2606da3be1a86fbcd
MD5 563d508458e581e2dbbf0816dcbf93b3
BLAKE2b-256 210a5aa9e3badfd6883b5c1e1cfeca019fd20459161b306195dd837a58f0edea

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