Commit 9edb72f
committed
feat(lftest): add attach_tests() helper for accurate test discovery
The prevailing pattern in monitoring-plugins unit tests has been
class TestCheck(unittest.TestCase):
check = '../my-plugin'
def test(self):
for t in TESTS:
with self.subTest(id=t['id']):
lib.lftest.run(self, self.check, t)
That works in the sense that every testcase still runs, but unittest
counts the surrounding `test` method as **one** test regardless of
how many fixtures the TESTS list contains. Running `./run` therefore
reports `Ran 1 test in ...s` even when the file exercises 24, 56 or
more scenarios, and `./run -v` is unhelpful because it only lists
the single method name.
`attach_tests(test_class, tests)` walks the TESTS list once at
import time and materialises one real `test_<sanitised id>` method
on the class. From unittest's point of view there are now N
individual tests with proper names, the test count is accurate and
verbose output lists every scenario.
The new pattern is one line:
class TestCheck(unittest.TestCase):
check = '../my-plugin'
lib.lftest.attach_tests(TestCheck, TESTS)1 parent efec109 commit 9edb72f
1 file changed
+68
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
97 | 164 | | |
98 | 165 | | |
99 | 166 | | |
| |||
0 commit comments