{"id":18084845,"url":"https://github.com/jwodder/pytest-fail-slow","last_synced_at":"2025-04-12T20:09:44.564Z","repository":{"id":60722807,"uuid":"437050370","full_name":"jwodder/pytest-fail-slow","owner":"jwodder","description":"Fail tests that take too long to run","archived":false,"fork":false,"pushed_at":"2025-01-23T14:48:15.000Z","size":68,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T20:09:36.583Z","etag":null,"topics":["available-on-pypi","pytest","python","slow-tests","timeout"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwodder.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-10T16:52:10.000Z","updated_at":"2025-04-09T04:30:29.000Z","dependencies_parsed_at":"2023-01-31T01:55:13.290Z","dependency_job_id":"72aa45f1-5556-4ff9-a482-1001b2cc6066","html_url":"https://github.com/jwodder/pytest-fail-slow","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"fcd0a039e6a2104d59c3d19147c1c24957c69885"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fpytest-fail-slow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fpytest-fail-slow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fpytest-fail-slow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fpytest-fail-slow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwodder","download_url":"https://codeload.github.com/jwodder/pytest-fail-slow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625493,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["available-on-pypi","pytest","python","slow-tests","timeout"],"created_at":"2024-10-31T15:08:24.926Z","updated_at":"2025-04-12T20:09:44.542Z","avatar_url":"https://github.com/jwodder.png","language":"Python","readme":"|repostatus| |ci-status| |coverage| |pyversions| |conda| |license|\n\n.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg\n    :target: https://www.repostatus.org/#active\n    :alt: Project Status: Active — The project has reached a stable, usable\n          state and is being actively developed.\n\n.. |ci-status| 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.. |coverage| 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.. |pyversions| image:: https://img.shields.io/pypi/pyversions/pytest-fail-slow.svg\n    :target: https://pypi.org/project/pytest-fail-slow/\n\n.. |conda| 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.. |license| 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 \u003chttps://github.com/jwodder/pytest-fail-slow\u003e`_\n| `PyPI \u003chttps://pypi.org/project/pytest-fail-slow/\u003e`_\n| `Issues \u003chttps://github.com/jwodder/pytest-fail-slow/issues\u003e`_\n| `Changelog \u003chttps://github.com/jwodder/pytest-fail-slow/blob/master/CHANGELOG.md\u003e`_\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 \u003chttps://pip.pypa.io\u003e`_ 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\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 \u003e 5.0s\n\n(*New in version 0.6.0*) If you only want a given test to fail for being slow\nunder certain conditions — say, when running under CI or on a certain platform\n— supply the ``enabled`` keyword argument to the marker.  The value of\n``enabled`` can be either a boolean expression or a `condition string`_.  When\nthe ``enabled`` value evaluates to ``True`` (the default), the test will fail\nif its runtime exceeds the given duration; if it evaluates to ``False``, a\nlengthy runtime will not cause the test to fail.  Example usage:\n\n.. code:: python\n\n    import os\n    import pytest\n\n    @pytest.mark.fail_slow(\"5s\", enabled=\"CI\" in os.environ)\n    def test_something_that_needs_to_be_fast_in_ci():\n        ...\n\nAn an alternative or in addition to the marker, the ``--fail-slow DURATION``\noption can be passed to the ``pytest`` command to, in essence, apply the\n``fail_slow`` marker with the given cutoff to all tests that don't already have\nthe marker.  (As far as ``pytest`` is concerned, the option does not actually\ncause any markers to be added to any tests, in case your code cares about\nthat.)  If a test already has the ``fail_slow`` marker, the ``--fail-slow``\noption will have no effect on it.\n\nIf you want a test to fail for being slow only if the ``--fail-slow`` option is\ngiven, but you also want a different cutoff for the test than that passed to\nthe option, you can give the test a ``fail_slow`` marker that sets the desired\ncutoff and also sets ``enabled`` to a condition string that checks whether\n``--fail-slow`` has been given, like so:\n\n.. code:: python\n\n    import pytest\n\n    @pytest.mark.fail_slow(3, enabled=\"config.getoption('--fail-slow') is not None\")\n    def test_something_sometimes_sluggish():\n        ...\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\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 \u003e 5.0s\n\nLike ``fail_slow``, the ``fail_slow_setup`` marker takes an optional\n``enabled`` keyword argument that can be used to conditionally enable or\ndisable failure for slow setups.  There is also a ``--fail-slow-setup\nDURATION`` option that can be passed to ``pytest`` to, in essence, apply the\nmarker to all tests that don't already have it.\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``, ``μs``, ``micro``, ``microsec``, ``microseconds``\n\n.. _condition string: https://docs.pytest.org/en/8.2.x/historical-notes.html\n                      #conditions-as-strings-instead-of-booleans\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwodder%2Fpytest-fail-slow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwodder%2Fpytest-fail-slow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwodder%2Fpytest-fail-slow/lists"}