Пример #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
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_generate_objects_from_modules():
    modules = {'pytest_wish.utils': utils, 're': re}
    include_patterns = ['pytest_wish.utils:generate_objects_from_modules']
    objs = utils.generate_objects_from_modules(modules, include_patterns, module_blacklist={'re'})
    assert len(list(objs)) == 1
Пример #4
0
def test_generate_objects_from_modules():
    modules = {'pytest_wish.utils': utils, 're': re}
    include_patterns = ['pytest_wish.utils:generate_objects_from_modules']
    objs = utils.generate_objects_from_modules(modules, include_patterns, module_blacklist={'re'})
    assert len(list(objs)) == 1