1
+ from collections import namedtuple
1
2
from io import StringIO
2
3
from unittest import TestCase
3
4
4
5
from flaky ._flaky_plugin import _FlakyPlugin
5
6
from flaky .names import FlakyNames
6
7
7
- from genty import genty , genty_dataset
8
+ TestCaseDataset = namedtuple ("TestCaseDataset" ,
9
+ ['max_runs' , 'min_passes' , 'current_runs' , 'current_passes' , 'expect_fail' ])
8
10
9
-
10
- @genty
11
11
class TestFlakyPlugin (TestCase ):
12
+ _test_dataset = (
13
+ "default_not_started" : TestCaseDataset (2 , 1 , 0 , 0 , False ),
14
+ "default_one_failure" : TestCaseDataset (2 , 1 , 1 , 0 , False ),
15
+ "default_one_success" : TestCaseDataset (2 , 1 , 1 , 1 , False ),
16
+ "default_two_failures" : TestCaseDataset (2 , 1 , 2 , 0 , True ),
17
+ "default_one_failure_one_success" : TestCaseDataset (2 , 1 , 2 , 1 , False ),
18
+ "three_two_not_started" : TestCaseDataset (3 , 2 , 0 , 0 , False ),
19
+ "three_two_one_failure" : TestCaseDataset (3 , 2 , 1 , 0 , False ),
20
+ "three_two_one_success" : TestCaseDataset (3 , 2 , 1 , 1 , False ),
21
+ "three_two_two_failures" : TestCaseDataset (3 , 2 , 2 , 0 , True ),
22
+ "three_two_one_failure_one_success" : TestCaseDataset (3 , 2 , 2 , 1 , False ),
23
+ "three_two_two_successes" : TestCaseDataset (3 , 2 , 2 , 2 , False ),
24
+ )
25
+
12
26
def setUp (self ):
13
- super ().setUp ()
27
+ super (TestFlakyPlugin , self ).setUp ()
14
28
self ._flaky_plugin = _FlakyPlugin ()
15
29
16
30
def test_flaky_plugin_handles_non_ascii_byte_string_in_exception (self ):
@@ -24,43 +38,26 @@ def test_flaky_plugin_handles_non_ascii_byte_string_in_exception(self):
24
38
mock_message ,
25
39
)
26
40
27
- @genty_dataset (
28
- default_not_started = (2 , 1 , 0 , 0 , False ),
29
- default_one_failure = (2 , 1 , 1 , 0 , False ),
30
- default_one_success = (2 , 1 , 1 , 1 , False ),
31
- default_two_failures = (2 , 1 , 2 , 0 , True ),
32
- default_one_failure_one_success = (2 , 1 , 2 , 1 , False ),
33
- three_two_not_started = (3 , 2 , 0 , 0 , False ),
34
- three_two_one_failure = (3 , 2 , 1 , 0 , False ),
35
- three_two_one_success = (3 , 2 , 1 , 1 , False ),
36
- three_two_two_failures = (3 , 2 , 2 , 0 , True ),
37
- three_two_one_failure_one_success = (3 , 2 , 2 , 1 , False ),
38
- three_two_two_successes = (3 , 2 , 2 , 2 , False ),
39
- )
40
- def test_flaky_plugin_identifies_failure (
41
- self ,
42
- max_runs ,
43
- min_passes ,
44
- current_runs ,
45
- current_passes ,
46
- expect_fail ,
47
- ):
48
- flaky = {
49
- FlakyNames .CURRENT_PASSES : current_passes ,
50
- FlakyNames .CURRENT_RUNS : current_runs ,
51
- FlakyNames .MAX_RUNS : max_runs ,
52
- FlakyNames .MIN_PASSES : min_passes ,
53
- }
54
- # pylint:disable=protected-access
55
- self .assertEqual (
56
- self ._flaky_plugin ._has_flaky_test_failed (flaky ),
57
- expect_fail ,
58
- )
41
+ def test_flaky_plugin_identifies_failure (self ):
42
+ for test in _test_dataset :
43
+ with self .subTest (test ):
44
+ flaky = {
45
+ FlakyNames .CURRENT_PASSES : _test_dataset [test ].current_passes ,
46
+ FlakyNames .CURRENT_RUNS : _test_dataset [test ].current_runs ,
47
+ FlakyNames .MAX_RUNS : _test_dataset [test ].max_runs ,
48
+ FlakyNames .MIN_PASSES : _test_dataset [test ].min_passes ,
49
+ }
50
+ # pylint:disable=protected-access
51
+ self .assertEqual (
52
+ self ._flaky_plugin ._has_flaky_test_failed (flaky ),
53
+ _test_dataset [test ].expect_fail ,
54
+ )
59
55
60
- @genty_dataset ('ascii stuff' , 'ńőń ȁŝćȉȉ ŝƭȕƒƒ' )
61
- def test_write_unicode_to_stream (self , message ):
62
- stream = StringIO ()
63
- stream .write ('ascii stuff' )
64
- # pylint:disable=protected-access
65
- self ._flaky_plugin ._stream .write (message )
66
- self ._flaky_plugin ._add_flaky_report (stream )
56
+ def test_write_unicode_to_stream (self ):
57
+ for message in ('ascii stuff' , 'ńőń ȁŝćȉȉ ŝƭȕƒƒ' ):
58
+ with self .subTest (message ):
59
+ stream = StringIO ()
60
+ stream .write ('ascii stuff' )
61
+ # pylint:disable=protected-access
62
+ self ._flaky_plugin ._stream .write (message )
63
+ self ._flaky_plugin ._add_flaky_report (stream )
0 commit comments