3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
run mozbase tests from a manifest,
9
by default https://github.com/mozilla/mozbase/blob/master/test-manifest.ini
18
here = os.path.dirname(os.path.abspath(__file__))
21
"""return the unittests in a .py file"""
23
path = os.path.abspath(path)
25
assert os.path.exists(path)
26
directory = os.path.dirname(path)
27
sys.path.insert(0, directory) # insert directory into path for top-level imports
28
modname = os.path.splitext(os.path.basename(path))[0]
29
module = imp.load_source(modname, path)
30
sys.path.pop(0) # remove directory from global path
31
loader = unittest.TestLoader()
32
suite = loader.loadTestsFromModule(module)
34
unittests.append(test)
37
def main(args=sys.argv[1:]):
43
manifests = [os.path.join(here, 'test-manifest.ini')]
45
for manifest in manifests:
46
# ensure manifests exist
47
if not os.path.exists(manifest):
48
missing.append(manifest)
49
assert not missing, 'manifest%s not found: %s' % ((len(manifests) == 1 and '' or 's'), ', '.join(missing))
50
manifest = manifestparser.TestManifest(manifests=manifests)
53
tests = manifest.active_tests()
56
unittestlist.extend(unittests(test['path']))
59
suite = unittest.TestSuite(unittestlist)
60
runner = unittest.TextTestRunner()
61
results = runner.run(suite)
63
# exit according to results
64
sys.exit((results.failures or results.errors) and 1 or 0)
66
if __name__ == '__main__':