-
Notifications
You must be signed in to change notification settings - Fork 6
/
discover.py
37 lines (31 loc) · 1.06 KB
/
discover.py
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
# This file prints discovers all test cases and prints out their IDs.
import compat
from config import get_setting
import unittest
import argparse
class Discover:
def __init__(self):
self.tests = []
def flatten_results(self, iterable):
input = list(iterable)
while input:
item = input.pop(0)
try:
data = iter(item)
input = list(data) + input
except:
yield item
def collect_tests(self, dirname):
loader = unittest.TestLoader()
suite = loader.discover(dirname)
flatresults = list(self.flatten_results(suite))
self.tests = [r.id() for r in flatresults]
def print_tests(self):
print('\n'.join(self.tests).strip())
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--testdir', dest='testdir', default=get_setting('StartDir'), help='Directory to choose tests from')
options = parser.parse_args()
disc = Discover()
disc.collect_tests(options.testdir)
disc.print_tests()