1# coding: utf-8 2 3from __future__ import unicode_literals 4 5from unittest import TestCase 6 7from flaky import flaky 8 9# This is a series of tests that do not use the flaky decorator; the flaky 10# behavior is intended to be enabled with the --force-flaky option on the 11# command line. 12 13 14class ExampleTests(TestCase): 15 _threshold = -2 16 17 def test_something_flaky(self): 18 """ 19 Flaky will run this test twice. 20 It will fail once and then succeed once. 21 This ensures that we mark tests as flaky even if they don't have a 22 decorator when we use the command-line options. 23 """ 24 self._threshold += 1 25 if self._threshold < 0: 26 raise Exception("Threshold is not high enough.") 27 28 @flaky(3, 1) 29 def test_flaky_thing_that_fails_then_succeeds(self): 30 """ 31 Flaky will run this test 3 times. 32 It will fail twice and then succeed once. 33 This ensures that the flaky decorator overrides any command-line 34 options we specify. 35 """ 36 self._threshold += 1 37 if self._threshold < 1: 38 raise Exception("Threshold is not high enough.") 39 40 41@flaky(3, 1) 42class ExampleFlakyTests(TestCase): 43 _threshold = -1 44 45 def test_flaky_thing_that_fails_then_succeeds(self): 46 """ 47 Flaky will run this test 3 times. 48 It will fail twice and then succeed once. 49 This ensures that the flaky decorator on a test suite overrides any 50 command-line options we specify. 51 """ 52 self._threshold += 1 53 if self._threshold < 1: 54 raise Exception("Threshold is not high enough.") 55