create test_flake unique per test

otherwise we will have race conditions
This commit is contained in:
Jörg Thalheim
2023-09-26 15:46:40 +02:00
parent 7eab8c22cf
commit 87aa063e86

View File

@@ -10,14 +10,8 @@ from root import CLAN_CORE
from clan_cli.dirs import nixpkgs_source from clan_cli.dirs import nixpkgs_source
@pytest.fixture(scope="module")
def monkeymodule() -> Iterator[pytest.MonkeyPatch]:
with pytest.MonkeyPatch.context() as mp:
yield mp
def create_flake( def create_flake(
monkeymodule: pytest.MonkeyPatch, name: str, clan_core_flake: Path | None = None monkeypatch: pytest.MonkeyPatch, name: str, clan_core_flake: Path | None = None
) -> Iterator[Path]: ) -> Iterator[Path]:
template = Path(__file__).parent / name template = Path(__file__).parent / name
# copy the template to a new temporary location # copy the template to a new temporary location
@@ -34,20 +28,20 @@ def create_flake(
line = line.replace("__CLAN_CORE__", str(clan_core_flake)) line = line.replace("__CLAN_CORE__", str(clan_core_flake))
print(line) print(line)
# check that an empty config is returned if no json file exists # check that an empty config is returned if no json file exists
monkeymodule.chdir(flake) monkeypatch.chdir(flake)
monkeymodule.setenv("HOME", str(home)) monkeypatch.setenv("HOME", str(home))
yield flake yield flake
@pytest.fixture(scope="module") @pytest.fixture
def test_flake(monkeymodule: pytest.MonkeyPatch) -> Iterator[Path]: def test_flake(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]:
yield from create_flake(monkeymodule, "test_flake") yield from create_flake(monkeypatch, "test_flake")
@pytest.fixture(scope="module") @pytest.fixture
def test_flake_with_core(monkeymodule: pytest.MonkeyPatch) -> Iterator[Path]: def test_flake_with_core(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]:
if not (CLAN_CORE / "flake.nix").exists(): if not (CLAN_CORE / "flake.nix").exists():
raise Exception( raise Exception(
"clan-core flake not found. This test requires the clan-core flake to be present" "clan-core flake not found. This test requires the clan-core flake to be present"
) )
yield from create_flake(monkeymodule, "test_flake_with_core", CLAN_CORE) yield from create_flake(monkeypatch, "test_flake_with_core", CLAN_CORE)