pytest-fail-slow


Namepytest-fail-slow JSON
Version 0.5.0 PyPI version JSON
download
home_page
SummaryFail tests that take too long to run
upload_time2024-02-11 12:03:01
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords pytest slow tests timeout
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://www.repostatus.org/badges/latest/active.svg
    :target: https://www.repostatus.org/#active
    :alt: Project Status: Active — The project has reached a stable, usable
          state and is being actively developed.

.. image:: https://github.com/jwodder/pytest-fail-slow/actions/workflows/test.yml/badge.svg
    :target: https://github.com/jwodder/pytest-fail-slow/actions/workflows/test.yml
    :alt: CI Status

.. image:: https://codecov.io/gh/jwodder/pytest-fail-slow/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jwodder/pytest-fail-slow

.. image:: https://img.shields.io/pypi/pyversions/pytest-fail-slow.svg
    :target: https://pypi.org/project/pytest-fail-slow/

.. image:: https://img.shields.io/conda/vn/conda-forge/pytest-fail-slow.svg
    :target: https://anaconda.org/conda-forge/pytest-fail-slow
    :alt: Conda Version

.. image:: https://img.shields.io/github/license/jwodder/pytest-fail-slow.svg
    :target: https://opensource.org/licenses/MIT
    :alt: MIT License

`GitHub <https://github.com/jwodder/pytest-fail-slow>`_
| `PyPI <https://pypi.org/project/pytest-fail-slow/>`_
| `Issues <https://github.com/jwodder/pytest-fail-slow/issues>`_
| `Changelog <https://github.com/jwodder/pytest-fail-slow/blob/master/CHANGELOG.md>`_

``pytest-fail-slow`` is a pytest_ plugin for treating tests as failed if they
took too long to run.  It adds markers for failing tests if they or their setup
stages run for longer than a given duration, along with command-line options
for applying the same cutoff to all tests.

Note that slow tests will still be run to completion; if you want them to
instead be stopped early, use pytest-timeout_.

.. _pytest: https://docs.pytest.org
.. _pytest-timeout: https://github.com/pytest-dev/pytest-timeout


Installation
============
``pytest-fail-slow`` requires Python 3.8 or higher and pytest 7.0 or higher.
Just use `pip <https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to
install it::

    python3 -m pip install pytest-fail-slow


Usage
=====

Failing Slow Tests
------------------

To cause a specific test to fail if it takes too long to run, apply the
``fail_slow`` marker to it, with the desired cutoff time as the argument:

.. code:: python

    import pytest

    @pytest.mark.fail_slow("5s")
    def test_something_sluggish():
        ...

In addition, the ``--fail-slow DURATION`` option can be passed to the
``pytest`` command to affect all tests in that run.  If ``--fail-slow`` is
given and a test has the ``fail_slow`` marker, the duration given by the marker
takes precedence for that test.

If a test fails due to being slow, pytest's output will include the test's
duration and the duration threshold, like so::

    ________________________________ test_func ________________________________
    Test passed but took too long to run: Duration 123.0s > 5.0s

**Note:** This feature only takes the durations for tests themselves into
consideration.  If a test passes in less than the specified duration, but one
or more fixture setups/teardowns take longer than the duration, the test will
still be marked as passing.  To fail a test if the setup takes too long, see
below.


Failing Slow Setups
-------------------

*New in version 0.4.0*

To cause a specific test to fail if the setup steps for all of its fixtures
combined take too long to run, apply the ``fail_slow_setup`` marker to it, with
the desired cutoff time as the argument:

.. code:: python

    import pytest

    @pytest.mark.fail_slow_setup("5s")
    def test_costly_resource(slow_to_create):
        ...

Do not apply the marker to the test's fixtures; markers have no effect on
fixtures.

In addition, the ``--fail-slow-setup DURATION`` option can be passed to the
``pytest`` command to affect all tests in that run.  If ``--fail-slow-setup``
is given and a test has the ``fail_slow_setup`` marker, the duration given by
the marker takes precedence for that test.

If the setup for a test takes too long to run, the test will be marked as
"errored," the test itself will not be run, and pytest's output will include
the setup stage's duration and the duration threshold, like so::

    _______________________ ERROR at setup of test_func _______________________
    Setup passed but took too long to run: Duration 123.0s > 5.0s

**Note:** If a test depends on multiple fixtures and just one of them exceeds
the given duration on its own, the remaining fixtures will still have their
setup steps run.  Also, all fixture teardowns will still be run after the test
would have run.


Specifying Durations
--------------------

A duration passed to a marker or command-line option can be either a bare
number of seconds or else a floating-point number followed by one of the
following units (case insensitive):

- ``h``, ``hour``, ``hours``
- ``m``, ``min``, ``mins``, ``minute``, ``minutes``
- ``s``, ``sec``, ``secs``, ``second``, ``seconds``
- ``ms``, ``milli``, ``millisec``, ``milliseconds``
- ``us``, ``μs``, ``micro``, ``microsec``, ``microseconds``

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-fail-slow",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "pytest,slow tests,timeout",
    "author": "",
    "author_email": "John Thorvald Wodder II <pytest-fail-slow@varonathe.org>",
    "download_url": "https://files.pythonhosted.org/packages/3c/0e/7720ced26fd3d3e2723352a6b5aacfa05dad13829796faed336620e716b9/pytest_fail_slow-0.5.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://www.repostatus.org/badges/latest/active.svg\n    :target: https://www.repostatus.org/#active\n    :alt: Project Status: Active \u2014 The project has reached a stable, usable\n          state and is being actively developed.\n\n.. image:: https://github.com/jwodder/pytest-fail-slow/actions/workflows/test.yml/badge.svg\n    :target: https://github.com/jwodder/pytest-fail-slow/actions/workflows/test.yml\n    :alt: CI Status\n\n.. image:: https://codecov.io/gh/jwodder/pytest-fail-slow/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jwodder/pytest-fail-slow\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-fail-slow.svg\n    :target: https://pypi.org/project/pytest-fail-slow/\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/pytest-fail-slow.svg\n    :target: https://anaconda.org/conda-forge/pytest-fail-slow\n    :alt: Conda Version\n\n.. image:: https://img.shields.io/github/license/jwodder/pytest-fail-slow.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: MIT License\n\n`GitHub <https://github.com/jwodder/pytest-fail-slow>`_\n| `PyPI <https://pypi.org/project/pytest-fail-slow/>`_\n| `Issues <https://github.com/jwodder/pytest-fail-slow/issues>`_\n| `Changelog <https://github.com/jwodder/pytest-fail-slow/blob/master/CHANGELOG.md>`_\n\n``pytest-fail-slow`` is a pytest_ plugin for treating tests as failed if they\ntook too long to run.  It adds markers for failing tests if they or their setup\nstages run for longer than a given duration, along with command-line options\nfor applying the same cutoff to all tests.\n\nNote that slow tests will still be run to completion; if you want them to\ninstead be stopped early, use pytest-timeout_.\n\n.. _pytest: https://docs.pytest.org\n.. _pytest-timeout: https://github.com/pytest-dev/pytest-timeout\n\n\nInstallation\n============\n``pytest-fail-slow`` requires Python 3.8 or higher and pytest 7.0 or higher.\nJust use `pip <https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to\ninstall it::\n\n    python3 -m pip install pytest-fail-slow\n\n\nUsage\n=====\n\nFailing Slow Tests\n------------------\n\nTo cause a specific test to fail if it takes too long to run, apply the\n``fail_slow`` marker to it, with the desired cutoff time as the argument:\n\n.. code:: python\n\n    import pytest\n\n    @pytest.mark.fail_slow(\"5s\")\n    def test_something_sluggish():\n        ...\n\nIn addition, the ``--fail-slow DURATION`` option can be passed to the\n``pytest`` command to affect all tests in that run.  If ``--fail-slow`` is\ngiven and a test has the ``fail_slow`` marker, the duration given by the marker\ntakes precedence for that test.\n\nIf a test fails due to being slow, pytest's output will include the test's\nduration and the duration threshold, like so::\n\n    ________________________________ test_func ________________________________\n    Test passed but took too long to run: Duration 123.0s > 5.0s\n\n**Note:** This feature only takes the durations for tests themselves into\nconsideration.  If a test passes in less than the specified duration, but one\nor more fixture setups/teardowns take longer than the duration, the test will\nstill be marked as passing.  To fail a test if the setup takes too long, see\nbelow.\n\n\nFailing Slow Setups\n-------------------\n\n*New in version 0.4.0*\n\nTo cause a specific test to fail if the setup steps for all of its fixtures\ncombined take too long to run, apply the ``fail_slow_setup`` marker to it, with\nthe desired cutoff time as the argument:\n\n.. code:: python\n\n    import pytest\n\n    @pytest.mark.fail_slow_setup(\"5s\")\n    def test_costly_resource(slow_to_create):\n        ...\n\nDo not apply the marker to the test's fixtures; markers have no effect on\nfixtures.\n\nIn addition, the ``--fail-slow-setup DURATION`` option can be passed to the\n``pytest`` command to affect all tests in that run.  If ``--fail-slow-setup``\nis given and a test has the ``fail_slow_setup`` marker, the duration given by\nthe marker takes precedence for that test.\n\nIf the setup for a test takes too long to run, the test will be marked as\n\"errored,\" the test itself will not be run, and pytest's output will include\nthe setup stage's duration and the duration threshold, like so::\n\n    _______________________ ERROR at setup of test_func _______________________\n    Setup passed but took too long to run: Duration 123.0s > 5.0s\n\n**Note:** If a test depends on multiple fixtures and just one of them exceeds\nthe given duration on its own, the remaining fixtures will still have their\nsetup steps run.  Also, all fixture teardowns will still be run after the test\nwould have run.\n\n\nSpecifying Durations\n--------------------\n\nA duration passed to a marker or command-line option can be either a bare\nnumber of seconds or else a floating-point number followed by one of the\nfollowing units (case insensitive):\n\n- ``h``, ``hour``, ``hours``\n- ``m``, ``min``, ``mins``, ``minute``, ``minutes``\n- ``s``, ``sec``, ``secs``, ``second``, ``seconds``\n- ``ms``, ``milli``, ``millisec``, ``milliseconds``\n- ``us``, ``\u03bcs``, ``micro``, ``microsec``, ``microseconds``\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Fail tests that take too long to run",
    "version": "0.5.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/jwodder/pytest-fail-slow/issues",
        "Source Code": "https://github.com/jwodder/pytest-fail-slow"
    },
    "split_keywords": [
        "pytest",
        "slow tests",
        "timeout"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02be5ae7ad60612ab291721ce875c2de907b18f895cf00db989bd7333e7b948a",
                "md5": "cf8ee26d7b20edcb477f9a3938ea2054",
                "sha256": "e5c8b388d20c5ed06bedb90bc33c5af9f5767c11e5d5d04169c0155dce5a9d5f"
            },
            "downloads": -1,
            "filename": "pytest_fail_slow-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf8ee26d7b20edcb477f9a3938ea2054",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5857,
            "upload_time": "2024-02-11T12:03:00",
            "upload_time_iso_8601": "2024-02-11T12:03:00.220368Z",
            "url": "https://files.pythonhosted.org/packages/02/be/5ae7ad60612ab291721ce875c2de907b18f895cf00db989bd7333e7b948a/pytest_fail_slow-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c0e7720ced26fd3d3e2723352a6b5aacfa05dad13829796faed336620e716b9",
                "md5": "7c6595c7615c951b88c03fa14299b752",
                "sha256": "fbfc3de71e9376a33c128324ef5e4826d8a8ea262b71abbc614f213508f619bd"
            },
            "downloads": -1,
            "filename": "pytest_fail_slow-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7c6595c7615c951b88c03fa14299b752",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7692,
            "upload_time": "2024-02-11T12:03:01",
            "upload_time_iso_8601": "2024-02-11T12:03:01.461422Z",
            "url": "https://files.pythonhosted.org/packages/3c/0e/7720ced26fd3d3e2723352a6b5aacfa05dad13829796faed336620e716b9/pytest_fail_slow-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 12:03:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jwodder",
    "github_project": "pytest-fail-slow",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-fail-slow"
}
        
Elapsed time: 0.18353s