Skip to content

Commit

Permalink
test_replace_env_var_circular_flip_flop: assert on circular log message
Browse files Browse the repository at this point in the history
Ensure that a true circular chain of env vars logs the correct error message.
  • Loading branch information
masenf committed Jan 16, 2023
1 parent db9fe18 commit 52fed10
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/config/loader/ini/replace/test_replace_env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from tests.config.loader.ini.replace.conftest import ReplaceOne
from tox.pytest import MonkeyPatch
from tox.pytest import LogCaptureFixture, MonkeyPatch


def test_replace_env_set(replace_one: ReplaceOne, monkeypatch: MonkeyPatch) -> None:
Expand Down Expand Up @@ -111,12 +111,34 @@ def avoid_infinite_loop() -> None: # pragma: no cover


@pytest.mark.usefixtures("reset_env_var_after_delay")
def test_replace_env_var_circular_flip_flop(replace_one: ReplaceOne, monkeypatch: MonkeyPatch) -> None:
def test_replace_env_var_circular_flip_flop(
replace_one: ReplaceOne,
monkeypatch: MonkeyPatch,
caplog: LogCaptureFixture,
) -> None:
"""Replacement values will not infinitely loop back and forth"""
monkeypatch.setenv("TRAGIC", "{env:MAGIC}")
monkeypatch.setenv("MAGIC", "{env:TRAGIC}")
result = replace_one("{env:MAGIC}")
assert result == "{env:MAGIC}"
assert "circular chain between set env MAGIC, TRAGIC" in caplog.messages


@pytest.mark.usefixtures("reset_env_var_after_delay")
def test_replace_env_var_circular_flip_flop_5(
replace_one: ReplaceOne,
monkeypatch: MonkeyPatch,
caplog: LogCaptureFixture,
) -> None:
"""Replacement values will not infinitely loop back and forth (longer chain)"""
monkeypatch.setenv("MAGIC", "{env:TRAGIC}")
monkeypatch.setenv("TRAGIC", "{env:RABBIT}")
monkeypatch.setenv("RABBIT", "{env:HAT}")
monkeypatch.setenv("HAT", "{env:TRICK}")
monkeypatch.setenv("TRICK", "{env:MAGIC}")
result = replace_one("{env:MAGIC}")
assert result == "{env:MAGIC}"
assert "circular chain between set env MAGIC, TRAGIC, RABBIT, HAT, TRICK" in caplog.messages


@pytest.mark.parametrize("fallback", [True, False])
Expand Down

0 comments on commit 52fed10

Please sign in to comment.