コード例 #1
0
def pytest_configure(config):
    # take over utils logging
    utils.logger.propagate = False
    utils.logger.setLevel(logging.DEBUG)  # FIXME: loglevel should be configurable
    utils.logger.addHandler(PytestHandler(config=config))

    # build the object index
    wish_specs = config.getoption('wish_specs')
    utils.import_distributions(wish_specs)

    wish_modules = config.getoption('wish_modules')
    utils.import_modules(wish_modules)

    wish_includes = config.getoption('wish_includes') or wish_modules
    wish_excludes = config.getoption('wish_excludes')
    wish_predicate = config.getoption('wish_predicate')

    # NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
    modules = sys.modules.copy()
    object_index = dict(
        utils.generate_objects_from_modules(modules, wish_includes, wish_excludes, wish_predicate)
    )

    wish_objects = config.getoption('wish_objects')
    if wish_objects is not None:
        object_index.update(utils.generate_objects_from_names(wish_objects))

    # store options
    config._wish_index_items = list(zip(*sorted(object_index.items()))) or [(), ()]
    config._wish_timeout = config.getoption('wish_timeout')
    config._wish_fail = config.getoption('wish_fail')
コード例 #2
0
ファイル: __init__.py プロジェクト: The-Compiler/pytest-wish
def pytest_sessionstart(session):
    config = session.config

    # take over utils logging
    utils.logger.propagate = False
    utils.logger.setLevel(logging.DEBUG)  # FIXME: loglevel should be configurable
    utils.logger.addHandler(PytestHandler(config=config))

    # build the object index
    wish_specs = config.getoption('wish_specs')
    utils.import_distributions(wish_specs)

    wish_modules = config.getoption('wish_modules')
    utils.import_modules(wish_modules)

    wish_includes = config.getoption('wish_includes') or wish_modules
    wish_excludes = config.getoption('wish_excludes')
    wish_predicate = config.getoption('wish_predicate')

    # NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
    modules = sys.modules.copy()
    object_index = dict(
        utils.generate_objects_from_modules(modules, wish_includes, wish_excludes, wish_predicate)
    )

    wish_objects = config.getoption('wish_objects')
    if wish_objects is not None:
        object_index.update(utils.generate_objects_from_names(wish_objects))

    # store options
    config._wish_index_items = list(zip(*sorted(object_index.items()))) or [(), ()]
    config._wish_timeout = config.getoption('wish_timeout')
    config._wish_fail = config.getoption('wish_fail')
コード例 #3
0
def test_import_modules():
    assert len(utils.import_modules(['pytest_wish'])) == 1
    assert len(utils.import_modules(['pytest_wish'], module_blacklist={'pytest_wish'})) == 0
    assert len(utils.import_modules(['non_existent_module'])) == 0
コード例 #4
0
def test_import_modules():
    assert len(utils.import_modules(['pytest_wish'])) == 1
    assert len(utils.import_modules(['pytest_wish'], module_blacklist={'pytest_wish'})) == 0
    assert len(utils.import_modules(['non_existent_module'])) == 0