pytest-is-running


Namepytest-is-running JSON
Version 1.5.1 PyPI version JSON
download
home_page
Summarypytest plugin providing a function to check if pytest is running.
upload_time2024-01-02 23:05:37
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =================
pytest-is-running
=================

.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pytest-is-running/main.yml?branch=main&style=for-the-badge
   :target: https://github.com/adamchainz/pytest-is-running/actions?workflow=CI

.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge
  :target: https://github.com/adamchainz/pytest-is-running/actions?workflow=CI

.. image:: https://img.shields.io/pypi/v/pytest-is-running.svg?style=for-the-badge
   :target: https://pypi.org/project/pytest-is-running/

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
   :target: https://github.com/psf/black

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
   :target: https://github.com/pre-commit/pre-commit
   :alt: 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:

.. code-block:: python

    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 <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.
I created pytest-is-running whilst working on the book!

----

Installation
============

Install with:

.. code-block:: bash

    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:

.. code-block:: python

    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 <https://docs.pytest.org/en/latest/example/simple.html#detect-if-running-from-within-a-pytest-run>`__.
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 <https://github.com/pytest-dev/pytest/issues/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:

.. code-block:: python

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-is-running",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "pytest",
    "author": "",
    "author_email": "Adam Johnson <me@adamj.eu>",
    "download_url": "https://files.pythonhosted.org/packages/46/4d/a7c4a16f74661bed99607182f6f87844ab84dab89579aaf4f296318f8097/pytest-is-running-1.5.1.tar.gz",
    "platform": null,
    "description": "=================\npytest-is-running\n=================\n\n.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pytest-is-running/main.yml?branch=main&style=for-the-badge\n   :target: https://github.com/adamchainz/pytest-is-running/actions?workflow=CI\n\n.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge\n  :target: https://github.com/adamchainz/pytest-is-running/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/pytest-is-running.svg?style=for-the-badge\n   :target: https://pypi.org/project/pytest-is-running/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n   :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge\n   :target: https://github.com/pre-commit/pre-commit\n   :alt: pre-commit\n\npytest plugin providing a function to check if pytest is running.\n\nUnmaintained (2024-01-02)\n=========================\n\nI stopped maintaining this package as it doesn\u2019t provide much value over checking whether pytest has been imported:\n\n.. code-block:: python\n\n    import sys\n\n    if \"pytest\" in sys.modules:\n        ...\n\nIn every project I\u2019ve seen, pytest is only imported when running.\n\n----\n\n**Working on a Django project?**\nCheck out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.\nI created pytest-is-running whilst working on the book!\n\n----\n\nInstallation\n============\n\nInstall with:\n\n.. code-block:: bash\n\n    python -m pip install pytest-is-running\n\nPython 3.8 to 3.12 supported.\n\nUsage\n=====\n\npytest will automatically find the plugin and use it when you run ``pytest``.\nYou can check if pytest is running with the ``is_running()`` function:\n\n.. code-block:: python\n\n    import pytest_is_running\n\n\n    if pytest_is_running.is_running():\n        ...\n\nThe package avoids importing pytest if it is not running, so that you don\u2019t incur that overhead in non-test paths.\n\nThe package registers its plugin hooks as early as possible in pytest\u2019s process, so it should be loaded before any of your non-test modules.\n\nRationale\n=========\n\nThis plugin is an alternative to re-implementing `the pattern in the pytest documentation <https://docs.pytest.org/en/latest/example/simple.html#detect-if-running-from-within-a-pytest-run>`__.\nAs a plugin, it is loaded earlier than ``conftest.py`` or any other code in your project.\nThis makes it a more robust way of checking whether pytest is currently running.\n\nUpstream `issue #9502 <https://github.com/pytest-dev/pytest/issues/9502>`__ discusses adding a feature to pytest.\nIt also covers an alternative which is often \u201cgood enough\u201d - a simple check if pytest has been imported with:\n\n.. code-block:: python\n\n    \"pytest\" in sys.modules\n\nThis won\u2019t be strictly accurate if you happen to import pytest outside of your test run, but that is not very common.\nYou may prefer to using this simpler technique instead of this plugin.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pytest plugin providing a function to check if pytest is running.",
    "version": "1.5.1",
    "project_urls": {
        "Changelog": "https://github.com/adamchainz/pytest-is-running/blob/main/CHANGELOG.rst",
        "Funding": "https://adamj.eu/books/",
        "Repository": "https://github.com/adamchainz/pytest-is-running"
    },
    "split_keywords": [
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "544555a7d7ef1a908d92cb01ecdad5f6e10f941b972087c4dd0cd16fc27f5b5f",
                "md5": "ac8908530342105cee6b49d7b1ec7719",
                "sha256": "d08ef02b59b67df57bd4766ba8e4a715a867e03e4b7abc193f14dff5666c2a3f"
            },
            "downloads": -1,
            "filename": "pytest_is_running-1.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ac8908530342105cee6b49d7b1ec7719",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4486,
            "upload_time": "2024-01-02T23:05:35",
            "upload_time_iso_8601": "2024-01-02T23:05:35.908066Z",
            "url": "https://files.pythonhosted.org/packages/54/45/55a7d7ef1a908d92cb01ecdad5f6e10f941b972087c4dd0cd16fc27f5b5f/pytest_is_running-1.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "464da7c4a16f74661bed99607182f6f87844ab84dab89579aaf4f296318f8097",
                "md5": "e3df98c30a7f7aa2f2f8c2ba19e86fcd",
                "sha256": "885cc87e5e3874d80f1f4610967c20430c2c169b2b2e6227da43a7b80dbe8a73"
            },
            "downloads": -1,
            "filename": "pytest-is-running-1.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e3df98c30a7f7aa2f2f8c2ba19e86fcd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4465,
            "upload_time": "2024-01-02T23:05:37",
            "upload_time_iso_8601": "2024-01-02T23:05:37.698226Z",
            "url": "https://files.pythonhosted.org/packages/46/4d/a7c4a16f74661bed99607182f6f87844ab84dab89579aaf4f296318f8097/pytest-is-running-1.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-02 23:05:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adamchainz",
    "github_project": "pytest-is-running",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-is-running"
}
        
Elapsed time: 0.30709s