{"id":13937385,"url":"https://github.com/box/flaky","last_synced_at":"2025-05-14T23:05:51.766Z","repository":{"id":15794757,"uuid":"18534090","full_name":"box/flaky","owner":"box","description":"Plugin for nose or pytest that automatically reruns flaky tests.","archived":false,"fork":false,"pushed_at":"2024-04-10T19:32:33.000Z","size":977,"stargazers_count":389,"open_issues_count":33,"forks_count":59,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-13T19:49:59.615Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/box.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","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":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-07T20:56:37.000Z","updated_at":"2025-04-01T16:45:27.000Z","dependencies_parsed_at":"2024-03-20T20:34:42.706Z","dependency_job_id":"b9b3f360-42b0-4a24-9902-58740d85a6df","html_url":"https://github.com/box/flaky","commit_stats":{"total_commits":156,"total_committers":25,"mean_commits":6.24,"dds":"0.47435897435897434","last_synced_commit":"1e8c954e7bc818452510d0d4bbcad1d565ddd4d1"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Fflaky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Fflaky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Fflaky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Fflaky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/box","download_url":"https://codeload.github.com/box/flaky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243358,"owners_count":22038046,"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":[],"created_at":"2024-08-07T23:03:33.731Z","updated_at":"2025-05-14T23:05:46.751Z","avatar_url":"https://github.com/box.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"flaky\n=====\n\n.. image:: http://opensource.box.com/badges/stable.svg\n    :target: http://opensource.box.com/badges\n\n.. image:: https://github.com/box/flaky/actions/workflows/tox.yml/badge.svg?branch=master\u0026event=push\n    :target: https://github.com/box/flaky/actions/workflows/tox.yml\n\n.. image:: https://img.shields.io/pypi/v/flaky.svg\n    :target: https://pypi.python.org/pypi/flaky\n\nAbout\n-----\n\nFlaky is a plugin for pytest that automatically reruns flaky tests.\n\nIdeally, tests reliably pass or fail, but sometimes test fixtures must rely on components that aren't 100%\nreliable. With flaky, instead of removing those tests or marking them to @skip, they can be automatically\nretried.\n\nFor more information about flaky, see `this presentation \u003chttp://opensource.box.com/flaky/\u003e`_.\n\nMarking tests flaky\n~~~~~~~~~~~~~~~~~~~\n\nTo mark a test as flaky, simply import flaky and decorate the test with @flaky:\n\n.. code-block:: python\n\n    from flaky import flaky\n\n.. code-block:: python\n\n    @flaky\n    def test_something_that_usually_passes(self):\n        value_to_double = 21\n        result = get_result_from_flaky_doubler(value_to_double)\n        self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')\n\nBy default, flaky will retry a failing test once, but that behavior can be overridden by passing values to the\nflaky decorator. It accepts two parameters: max_runs, and min_passes; flaky will run tests up to max_runs times, until\nit has succeeded min_passes times. Once a test passes min_passes times, it's considered a success; once it has been\nrun max_runs times without passing min_passes times, it's considered a failure.\n\n.. code-block:: python\n\n    @flaky(max_runs=3, min_passes=2)\n    def test_something_that_usually_passes(self):\n        \"\"\"This test must pass twice, and it can be run up to three times.\"\"\"\n        value_to_double = 21\n        result = get_result_from_flaky_doubler(value_to_double)\n        self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')\n\nMarking a class flaky\n+++++++++++++++++++++\n\nIn addition to marking a single test flaky, entire test cases can be marked flaky:\n\n.. code-block:: python\n\n    @flaky\n    class TestMultipliers(TestCase):\n        def test_flaky_doubler(self):\n            value_to_double = 21\n            result = get_result_from_flaky_doubler(value_to_double)\n            self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')\n\n        @flaky(max_runs=3)\n        def test_flaky_tripler(self):\n            value_to_triple = 14\n            result = get_result_from_flaky_tripler(value_to_triple)\n            self.assertEqual(result, value_to_triple * 3, 'Result tripled incorrectly.')\n\nThe @flaky class decorator will mark test_flaky_doubler as flaky, but it won't override the 3 max_runs\nfor test_flaky_tripler (from the decorator on that test method).\n\nPytest marker\n+++++++++++++\n\nWhen using ``pytest``, ``@pytest.mark.flaky`` can be used in place of ``@flaky``.\n\nDon't rerun certain types of failures\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nDepending on your tests, some failures are obviously not due to flakiness. Instead of rerunning\nafter those failures, you can specify a filter function that can tell flaky to fail the test right away.\n\n.. code-block:: python\n\n    def is_not_crash(err, *args):\n        return not issubclass(err[0], ProductCrashedError)\n\n    @flaky\n    def test_something():\n        raise ProductCrashedError\n\n    @flaky(rerun_filter=is_not_crash)\n    def test_something_else():\n        raise ProductCrashedError\n\nFlaky will run ``test_something`` twice, but will only run ``test_something_else`` once.\n\nIt can also be used to incur a delay between test retries:\n\n.. code-block:: python\n    \n    import time\n    \n    def delay_rerun(*args):\n        time.sleep(1)\n        return True\n    \n    @flaky(rerun_filter=delay_rerun)\n    def test_something_else():\n        ...\n\nActivating the plugin\n~~~~~~~~~~~~~~~~~~~~~\n\nWith pytest, flaky will automatically run. It can, however be disabled via the command line:\n\n.. code-block:: console\n\n    pytest -p no:flaky\n\nCommand line arguments\n~~~~~~~~~~~~~~~~~~~~~~\n\nNo Flaky Report\n+++++++++++++++\n\nPass ``--no-flaky-report`` to suppress the report at the end of the run detailing flaky test results.\n\nShorter Flaky Report\n++++++++++++++++++++\n\nPass ``--no-success-flaky-report`` to suppress information about successful flaky tests.\n\nForce Flaky\n+++++++++++\n\nPass ``--force-flaky`` to treat all tests as flaky.\n\nPass ``--max-runs=MAX_RUNS`` and/or ``--min-passes=MIN_PASSES`` to control the behavior of flaky if ``--force-flaky``\nis specified. Flaky decorators on individual tests will override these defaults.\n\n\n*Additional usage examples are in the code - see test/test_pytest/test_pytest_example.py*\n\nInstallation\n------------\n\nTo install, simply:\n\n.. code-block:: console\n\n    pip install flaky\n\n\nCompatibility\n-------------\n\nFlaky is tested with the following test runners and options:\n\n- Py.test. Works with ``pytest-xdist`` but not with the ``--boxed`` option. Doctests cannot be marked flaky.\n\n\nContributing\n------------\n\nSee `CONTRIBUTING.rst \u003chttps://github.com/box/flaky/blob/master/CONTRIBUTING.rst\u003e`_.\n\n\nSetup\n~~~~~\n\nCreate a virtual environment and install packages -\n\n.. code-block:: console\n\n    mkvirtualenv flaky\n    pip install -r requirements-dev.txt\n\n\nTesting\n~~~~~~~\n\nRun all tests using -\n\n.. code-block:: console\n\n    tox\n\nThe tox tests include code style checks via pycodestyle and pylint.\n\n\nCopyright and License\n---------------------\n\n::\n\n Copyright 2015 Box, Inc. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbox%2Fflaky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbox%2Fflaky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbox%2Fflaky/lists"}