Example #1
0
def project(request, pytestconfig):

    project_dir = get_populus_option(cmdline_option="--populus-project",
                                     ini_option="populus_project",
                                     environ_var="PYTEST_POPULUS_PROJECT",
                                     pytestconfig=pytestconfig,
                                     default=pytestconfig.args[0])

    if not os.path.exists(get_json_config_file_path(project_dir)):
        raise FileNotFoundError(
            "No populus project found for testing in {project_dir}".format(
                project_dir=project_dir))

    contracts = request.config.cache.get(CACHE_KEY_CONTRACTS, None)
    mtime = request.config.cache.get(CACHE_KEY_MTIME, None)

    project = Project(project_dir, create_config_file=True)

    project.fill_contracts_cache(contracts, mtime)
    request.config.cache.set(
        CACHE_KEY_CONTRACTS,
        normalize_object_for_json(project.compiled_contract_data),
    )
    request.config.cache.set(
        CACHE_KEY_MTIME,
        get_latest_mtime(project.get_all_source_file_paths()),
    )

    return project