blob: 041a2719f0cae345df4e81475e7151ea4a681d00 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002#
3# Copyright (C) 2012 Richard Purdie
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8import os
9import sys, logging
10sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
11
12import unittest
13try:
14 import bb
Brad Bishop19323692019-04-05 15:28:33 -040015 import hashserv
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080016 import layerindexlib
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017except RuntimeError as exc:
18 sys.exit(str(exc))
19
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020tests = ["bb.tests.codeparser",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080021 "bb.tests.cooker",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060022 "bb.tests.cow",
23 "bb.tests.data",
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 "bb.tests.event",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025 "bb.tests.fetch",
26 "bb.tests.parse",
Brad Bishop19323692019-04-05 15:28:33 -040027 "bb.tests.persist_data",
Brad Bishop96ff1982019-08-19 13:50:42 -040028 "bb.tests.runqueue",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029 "bb.tests.utils",
Brad Bishop19323692019-04-05 15:28:33 -040030 "hashserv.tests",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031 "layerindexlib.tests.layerindexobj",
32 "layerindexlib.tests.restapi",
33 "layerindexlib.tests.cooker"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034
35for t in tests:
36 t = '.'.join(t.split('.')[:3])
37 __import__(t)
38
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040# Set-up logging
41class StdoutStreamHandler(logging.StreamHandler):
42 """Special handler so that unittest is able to capture stdout"""
43 def __init__(self):
44 # Override __init__() because we don't want to set self.stream here
45 logging.Handler.__init__(self)
46
47 @property
48 def stream(self):
49 # We want to dynamically write wherever sys.stdout is pointing to
50 return sys.stdout
51
52
53handler = StdoutStreamHandler()
54bb.logger.addHandler(handler)
55bb.logger.setLevel(logging.DEBUG)
56
57
58ENV_HELP = """\
59Environment variables:
60 BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network
61 connection
62 BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories
63"""
64
65class main(unittest.main):
66 def _print_help(self, *args, **kwargs):
67 super(main, self)._print_help(*args, **kwargs)
68 print(ENV_HELP)
69
70
71if __name__ == '__main__':
72 main(defaultTest=tests, buffer=True)