File: test_flaky_decorator.py

package info (click to toggle)
python-flaky 3.3.0-1~bpo8%2B1
  • links: PTS
  • area: main
  • in suites: jessie-backports
  • size: 388 kB
  • sloc: python: 1,947; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding: utf-8

from __future__ import unicode_literals
from flaky.flaky_decorator import flaky
from flaky.names import FlakyNames
from test.test_case_base import TestCase


class TestFlakyDecorator(TestCase):
    def setUp(self):
        super(TestFlakyDecorator, self).setUp()

    def test_flaky_raises_for_non_positive_min_passes(self):
        def test_something():
            pass
        self.assertRaises(
            ValueError,
            lambda: flaky(min_passes=0)(test_something),
        )

    def test_flaky_raises_for_max_runs_less_than_min_passes(self):
        def test_something():
            pass
        self.assertRaises(
            ValueError,
            lambda: flaky(max_runs=2, min_passes=3)(test_something),
        )

    def test_flaky_adds_flaky_attributes_to_test_method(self):
        min_passes = 4
        max_runs = 7

        @flaky(max_runs, min_passes)
        def test_something():
            pass

        flaky_attribute = dict((
            (attr, getattr(
                test_something,
                attr,
                None
            )) for attr in FlakyNames()
        ))

        self.assertIsNotNone(flaky_attribute)
        self.assertDictContainsSubset(
            {
                FlakyNames.MIN_PASSES: min_passes,
                FlakyNames.MAX_RUNS: max_runs,
                FlakyNames.CURRENT_PASSES: 0,
                FlakyNames.CURRENT_RUNS: 0,
                FlakyNames.CURRENT_ERRORS: None
            },
            flaky_attribute
        )