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')
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')
def test_import_distributions(): # normal code path, pytest is a dependency distributions_modules = utils.import_distributions(['pytest-wish']) assert len(distributions_modules) == 1 requirement, distributions_modules = distributions_modules.popitem() assert requirement.startswith('pytest-wish==') assert set(distributions_modules) == {'pytest_wish'} distributions_modules = utils.import_distributions(['python']) assert len(distributions_modules) == 1 requirement, distributions_modules = distributions_modules.popitem() assert requirement.startswith('Python==') # assert 'os.path' in distributions_modules # fail code path distributions_modules = utils.import_distributions( ['pytest-wish', 'non_existent_dist'], distribution_blacklist={'pytest-wish'} ) assert len(distributions_modules) == 0