Skip to content

Commit 52fed10

Browse files
committed
test_replace_env_var_circular_flip_flop: assert on circular log message
Ensure that a true circular chain of env vars logs the correct error message.
1 parent db9fe18 commit 52fed10

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/config/loader/ini/replace/test_replace_env_var.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from tests.config.loader.ini.replace.conftest import ReplaceOne
9-
from tox.pytest import MonkeyPatch
9+
from tox.pytest import LogCaptureFixture, MonkeyPatch
1010

1111

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

112112

113113
@pytest.mark.usefixtures("reset_env_var_after_delay")
114-
def test_replace_env_var_circular_flip_flop(replace_one: ReplaceOne, monkeypatch: MonkeyPatch) -> None:
114+
def test_replace_env_var_circular_flip_flop(
115+
replace_one: ReplaceOne,
116+
monkeypatch: MonkeyPatch,
117+
caplog: LogCaptureFixture,
118+
) -> None:
115119
"""Replacement values will not infinitely loop back and forth"""
116120
monkeypatch.setenv("TRAGIC", "{env:MAGIC}")
117121
monkeypatch.setenv("MAGIC", "{env:TRAGIC}")
118122
result = replace_one("{env:MAGIC}")
119123
assert result == "{env:MAGIC}"
124+
assert "circular chain between set env MAGIC, TRAGIC" in caplog.messages
125+
126+
127+
@pytest.mark.usefixtures("reset_env_var_after_delay")
128+
def test_replace_env_var_circular_flip_flop_5(
129+
replace_one: ReplaceOne,
130+
monkeypatch: MonkeyPatch,
131+
caplog: LogCaptureFixture,
132+
) -> None:
133+
"""Replacement values will not infinitely loop back and forth (longer chain)"""
134+
monkeypatch.setenv("MAGIC", "{env:TRAGIC}")
135+
monkeypatch.setenv("TRAGIC", "{env:RABBIT}")
136+
monkeypatch.setenv("RABBIT", "{env:HAT}")
137+
monkeypatch.setenv("HAT", "{env:TRICK}")
138+
monkeypatch.setenv("TRICK", "{env:MAGIC}")
139+
result = replace_one("{env:MAGIC}")
140+
assert result == "{env:MAGIC}"
141+
assert "circular chain between set env MAGIC, TRAGIC, RABBIT, HAT, TRICK" in caplog.messages
120142

121143

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

0 commit comments

Comments
 (0)