Skip to content

Commit fa18d70

Browse files
committed
Install the local development version in integration tests
When doing integration tests we need to make sure that the repo-config dependency used is the one in development, otherwise tests will very likely fail as it will be using an old (released) version. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 66a9584 commit fa18d70

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/integration/test_cookiecutter_generation.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Generation tests for cookiecutter."""
55

66
import pathlib
7+
import re
78
import subprocess
89

910
import pytest
@@ -31,6 +32,10 @@ def test_generation(tmp_path: pathlib.Path, repo_type: str) -> None:
3132
repo_path = subdirs[0]
3233
_run(repo_path, "python3", "-m", "venv", ".venv")
3334

35+
_update_pyproject_repo_config_dep(
36+
repo_config_path=cwd, repo_type=repo_type, repo_path=repo_path
37+
)
38+
3439
cmd = ". .venv/bin/activate; pip install .[dev-noxfile]; nox"
3540
print()
3641
print(f"Running in shell [{cwd}]: {cmd}")
@@ -43,3 +48,27 @@ def _run(cwd: pathlib.Path, *cmd: str) -> subprocess.CompletedProcess[bytes]:
4348
print(f"Running [{cwd}]: {' '.join(cmd)}")
4449
print()
4550
return subprocess.run(cmd, cwd=cwd, check=True)
51+
52+
53+
def _update_pyproject_repo_config_dep(
54+
*, repo_config_path: pathlib.Path, repo_type: str, repo_path: pathlib.Path
55+
) -> None:
56+
"""Update the repo config dependency in the generated pyproject.toml.
57+
58+
This is necessary to make sure we are testing the local version of
59+
`frequenz-repo-config`, otherwise tests will fail because they will be running with
60+
an older (released) version of `frequenz-repo-config`.
61+
62+
Args:
63+
repo_config_path: Path to the local `frequenz-repo-config` repo.
64+
repo_type: Type of the repo to generate.
65+
repo_path: Path to the generated repo.
66+
"""
67+
repo_config_dep = f"frequenz-repo-config[{repo_type}] @ file://{repo_config_path}"
68+
repo_config_dep_re = re.compile(rf"""frequenz-repo-config\[{repo_type}\][^"]+""")
69+
70+
with open(repo_path / "pyproject.toml", encoding="utf8") as pyproject_file:
71+
pyproject_content = pyproject_file.read()
72+
73+
with open(repo_path / "pyproject.toml", "w", encoding="utf8") as pyproject_file:
74+
pyproject_file.write(repo_config_dep_re.sub(repo_config_dep, pyproject_content))

0 commit comments

Comments
 (0)