Ejemplo n.º 1
0
def test_generate_objects_from_names():
    # normal path
    names = ['pytest_wish.utils:generate_objects_from_names']
    assert len(list(utils.generate_objects_from_names(names))) == 1
    # error paths
    names = ['# comment', 'non_existent_module:', 'math:non_existent_object']
    assert len(list(utils.generate_objects_from_names(names))) == 0
Ejemplo n.º 2
0
def test_generate_objects_from_names():
    # normal path
    names = ['pytest_wish.utils:generate_objects_from_names']
    assert len(list(utils.generate_objects_from_names(names))) == 1
    # error paths
    names = ['# comment', 'non_existent_module:', 'math:non_existent_object']
    assert len(list(utils.generate_objects_from_names(names))) == 0
Ejemplo n.º 3
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')
Ejemplo n.º 4
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')