1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
4 from __future__ import print_function
9 def report_discovered(tests, parents, pretty=False, simple=False,
10 _send=print, **_ignored):
11 """Serialize the discovered tests and write to stdout."""
16 'testroot': test.path.root,
17 'relfile': test.path.relfile,
18 'lineno': test.lineno,
19 'testfunc': test.path.func,
20 'subtest': test.path.sub or None,
21 'markers': test.markers or [],
25 for parent in parents:
26 rootdir = parent.name if parent.root is None else parent.root
28 root = byroot[rootdir]
30 root = byroot[rootdir] = {
36 root['id'] = parent.id
38 root['parents'].append({
42 'parentid': parent.parentid,
45 # We are guaranteed that the parent was added.
46 root = byroot[test.path.root]
50 # TODO: Add a "kind" field
51 # (e.g. "unittest", "function", "doctest")
52 'source': test.source,
53 'markers': test.markers or [],
54 'parentid': test.parentid,
56 root['tests'].append(testdata)
58 'rootid': byroot[root]['id'],
60 'parents': byroot[root]['parents'],
61 'tests': byroot[root]['tests'],
62 } for root in sorted(byroot)]
70 separators=(',', ': '),
72 serialized = json.dumps(data, **kwargs)