Visitar URL original
fix(config): tie spliced set_env markers to their value by feiiiiii5 · Pull Request #4107 · tox-dev/tox · GitHub
Skip to content

fix(config): tie spliced set_env markers to their value - #4107

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
feiiiiii5:hunt/tox-run
Oct 1, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
feiiiiii5:hunt/tox-run

Conversation

@feiiiiii5

@feiiiiii5 feiiiiii5 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

A PEP-508 marker on a set_env line pulled in with {[section]set_env} could hide a value it did not come with. The
inline and TOML forms already tie a marker to its own value, and the pulled-in block now does the same.

[testenv:base]
set_env =
    FOO = inherited; sys_platform == "nonexistent"

[testenv:child]
set_env =
    {[testenv:base]set_env}
    FOO = own

tox config -e child -k set_env showed FOO=own, yet tox run -e child started the commands without FOO. Two more
layouts dropped the variable from the child while the parent kept it: a later unconditional line in the pulled-in block,
and an environment file loaded in it. Each command below prints os.environ.get("FOO"):

case                               parent     child before   child after
child sets FOO = own               None       None           own
parent redefines FOO = b           b          None           b
parent loads FOO from file|a.env   fromfile   None           fromfile

A false marker on a value that does win still hides it, and the tests cover that case too.

No issue tracks this. #4077 applied the same rule to the inline and TOML forms.

  • ran the linter to address style issues
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

_iter_needs_replacement, which expands a {[section]set_env} splice,
wrote the PEP-508 marker outside the branch that picks the winning value,
so a line that lost the key still installed a marker and suppressed the
value that won. Because the marker is installed lazily during iteration,
the key was present on the first read of the env and gone on every read
after, so one run disagreed with itself.

__init__ and _parse_dict both place the marker write inside the winner
branch; tox-dev#4077 fixed those two and left the splice path alone. The
siblings' `else: markers.pop(...)` is not copied here because it is
unreachable in this parser: once a key is in self._raw every later
spliced line with that key loses, so the branch runs at most once per key.
@gaborbernat gaborbernat changed the title Set a set_env marker only on the line that won the value fix(config): tie spliced set_env markers to their value Oct 1, 2026
Inside one {[section]set_env} block, an earlier conditional line kept
its marker after a later unconditional line or a file| entry redefined
the key, so the inheriting env dropped a variable its parent set. Clear
the marker when the winning line has none, and replace the unit tests
with real runs covering the inherited, redefined, file and still-gated
cases.
@gaborbernat
gaborbernat enabled auto-merge (squash) October 1, 2026 06:05
@gaborbernat
gaborbernat merged commit 66ec58c into tox-dev:main Oct 1, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants