in container_images/pytest/main.py [0:0]
def read_tox_ini(repo_root: Path, package_root: Path) -> TestConfig:
"""Read pyproject.toml and write a new tox.ini file.
The tox.ini file is generated to ensure that tests are run consistently,
and that test reports are written to the correct location.
"""
cfg = package_root / "pyproject.toml"
assert cfg.exists(), "Expected pyproject.toml to exist."
with cfg.open() as f:
project_cfg = toml.load(f)
# Read the [tool.gcp-guest-pytest] section of pyproject.toml.
test_cfg = project_cfg.get("tool", {}).get("gcp-guest-pytest", {})
# Which interpreters to enable.
envlist = [to_tox_version(env) for env in test_cfg.get("envlist", [])]
if not envlist:
raise ValueError(
"pyproject.toml must contain a section [tool.gcp-guest-pytest] "
"with a key `envlist` and at least one interpreter.")
pip_deps, local_deps = [], []
for dep in test_cfg.get("test-deps", []):
if dep.startswith("//"):
local = dep[2:]
if not (repo_root / local).exists():
raise ValueError("Dependency {} not found".format(dep))
local_deps.append(local)
else:
pip_deps.append(dep)
return TestConfig(
repo_root=repo_root,
package_root=package_root,
envlist=envlist,
pip_deps=pip_deps,
local_deps=local_deps
)