File: __init__.py

package info (click to toggle)
rdma-core 61.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: ansic: 176,798; python: 15,496; sh: 2,742; perl: 1,465; makefile: 73
file content (44 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2019 Mellanox Technologies, Inc . All rights reserved. See COPYING file

import importlib
import os

from args_parser import parser

# Load every test as a module in the system so that unittest's loader can find it
def _load_tests():
    res = []
    for fn in sorted(os.listdir(os.path.dirname(__file__))):
        if fn.endswith(".py") and fn.startswith("test_"):
            m  = importlib.import_module("." + os.path.basename(fn)[:-3], __name__)
            res.append(m)
    return res
__test_modules__ = _load_tests()

# unittest -v prints names like 'tests.test_foo', but it always starts
# searching from the tests module, adding the name 'tests.test' lets the user
# specify the same test name from logging on the command line to trivially run
# a single test.
tests = importlib.import_module(".", __name__)


def _show_tests_and_exit(loader, standard_tests, pattern):
    """
    Prints the full test names that are loaded with the current modules via
    loadTestsFromModule protocol, without modifying standard_tests.
    """
    for mod in __test_modules__:
        for test in loader.loadTestsFromModule(mod, pattern=pattern):
            for test_case in test:
                print(test_case.id())
    return standard_tests


def load_tests(loader, standard_tests, pattern):
    """Implement the loadTestsFromModule protocol"""
    if parser.args['list_tests']:
        return _show_tests_and_exit(loader, standard_tests, pattern)
    for mod in __test_modules__:
        standard_tests.addTests(loader.loadTestsFromModule(mod, pattern=pattern))
    return standard_tests