Skip to main content

Plugin for nose that automatically reruns flaky tests.

Project description

https://travis-ci.org/box/flaky.png?branch=master https://pypip.in/v/flaky/badge.png https://pypip.in/d/flaky/badge.png

Flaky is a plugin for nose that automatically reruns flaky tests.

Ideally, tests reliably pass or fail, but sometimes test fixtures must rely on components that aren’t 100% reliable. With flaky, instead of removing those tests or marking them to @skip, they can be automatically retried.

Like any nose plugin, flaky can be activated via the command line:

nosetests --with-flaky

To mark a test as flaky, simply decorate it with @flaky():

@flaky()
def test_something_that_usually_passes(self):
    value_to_double = 21
    result = get_result_from_flaky_doubler(value_to_double)
    self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')

By default, flaky will retry a failing test once, but that behavior can be overridden by passing values to the flaky decorator. It accepts two parameters: max_runs, and min_passes; flaky will run tests up to max_runs times, until it has succeeded min_passes times. Once a test passes min_passes times, it’s considered a success; once it has been run max_runs times without passing min_passes times, it’s considered a failure.

@flaky(3, 2)
def test_something_that_usually_passes(self):
    """This test must pass twice, and it can be run up to three times."""
    value_to_double = 21
    result = get_result_from_flaky_doubler(value_to_double)
    self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')

In addition to marking a single test flaky, entire test cases can be marked flaky:

@flaky()
class TestMultipliers(TestCase):
    def test_flaky_doubler(self):
        value_to_double = 21
        result = get_result_from_flaky_doubler(value_to_double)
        self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')

    @flaky(3)
    def test_flaky_tripler(self):
        value_to_triple = 14
        result = get_result_from_flaky_tripler(value_to_triple)
        self.assertEqual(result, value_to_triple * 3, 'Result tripled incorrectly.')

The @flaky() class decorator will mark test_flaky_doubler as flaky, but it won’t override the 3 max_runs for test_flaky_doubler (from the decorator on that test method).

Additional usage examples are in the code - see test/test_example.py

Installation

To install, simply:

pip install flaky

Contributing

See CONTRIBUTING.

Setup

Create a virtual environment and install packages -

mkvirtualenv flaky
pip install -r requirements-dev.txt

Testing

Run all tests using -

tox

The tox tests include code style checks via pep8 and pylint.

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

flaky-0.0.2.tar.gz (12.2 kB view details)

Uploaded Source

File details

Details for the file flaky-0.0.2.tar.gz.

File metadata

  • Download URL: flaky-0.0.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flaky-0.0.2.tar.gz
Algorithm Hash digest
SHA256 89cd8d1e6c2d3346e21193533e4be6a6db417cf60185a7e8f257e0d183583b86
MD5 a0c3e4d6828264bba164961c7e305c63
BLAKE2b-256 28029d62a00b60db5f68b68d54739d1345d3a7a4878b6d0dc21f10b0db993933

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page