Skip to content

spothero/flaky

 
 

Repository files navigation

flaky

image

image

image

image

About

Flaky is a plugin for nose or py.test 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.

For more information about flaky, see this presentation.

Marking tests flaky

To mark a test as flaky, simply import flaky and decorate the test with @flaky:

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.

Marking a class flaky

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

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

Don't rerun certain types of failures

Depending on your tests, some failures are obviously not due to flakiness. Instead of rerunning after those failures, you can specify a filter function that can tell flaky to fail the test right away.

Flaky will run test_something twice, but will only run test_something_else once.

Activating the plugin

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

nosetests --with-flaky

With py.test, flaky will automatically run. It can, however be disabled via the command line:

py.test -p no:flaky

Command line arguments

No Flaky Report

Pass --no-flaky-report to suppress the report at the end of the run detailing flaky test results.

Shorter Flaky Report

Pass --no-success-flaky-report to suppress information about successful flaky tests.

Force Flaky

Pass --force-flaky to treat all tests as flaky.

Pass --max-runs=MAX_RUNS and/or --min-passes=MIN_PASSES to control the behavior of flaky if --force-flaky is specified. Flaky decorators on individual tests will override these defaults.

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

Installation

To install, simply:

pip install flaky

Compatibility

Flaky is tested with the following test runners and options:

  • Nosetests. Doctests cannot be marked flaky.
  • Py.test. Works with pytest-xdist but not with the --boxed option. Doctests cannot be marked flaky.

Contributing

See CONTRIBUTING.rst.

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.

Copyright 2015 Box, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Plugin for nose or py.test that automatically reruns flaky tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%