def write_tox_ini()

in container_images/pytest/main.py [0:0]


def write_tox_ini(cfg: TestConfig, artifact_dir: Path, execution_root: Path):
  """Write the test config to 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.
  """

  config = configparser.ConfigParser()
  config["tox"] = {
    "envlist": ", ".join(cfg.envlist),
  }

  local_deps = []
  dep_dir = execution_root.absolute() / "deps"
  for d in cfg.local_deps:
    local_deps.append((dep_dir / d).as_posix())

  config["testenv"] = {
    "envlogdir":
      "{artifact_dir}/tox/{{envname}}".format(artifact_dir=artifact_dir),
    "deps":
      "\n\t".join(_common_test_deps + cfg.pip_deps + local_deps),
    "commands":
      " ".join(_per_interpreter_command).format(artifact_dir=artifact_dir),
  }

  if os.path.exists("tox.ini"):
    print("Removing existing tox.ini file.")
    os.remove("tox.ini")

  with open("tox.ini", "w") as f:
    config.write(f)