wntrblm / nox

Flexible test automation for Python
https://nox.thea.codes
Apache License 2.0
1.33k stars 151 forks source link

`include_outer_env=False` will include outer_env when `env` is not set #868

Open Wurstnase opened 1 month ago

Wurstnase commented 1 month ago

Current Behavior

On include_outer_env=False, all outer environment variable will be used, when env is not set or None.

Expected Behavior

When include_outer_env=False, no environment variables should be set. Also when no env is set. Current workaround is env={}

Steps To Reproduce

import nox

@nox.session
def env(session: Session):
    session.run("printenv", include_outer_env=False)
    session.run("printenv", include_outer_env=False, env={})

Environment

- OS: MacOS 15
- Python: 3.12.7
- Nox: 2024.4.15

Anything else?

No response

henryiii commented 3 weeks ago

Actually, I think there's a second bug. I believe VIRTUAL_ENV and CONDA_PREFIX don't get set if you use this option, as well.

Wurstnase commented 2 weeks ago

tox^1 do a lot of magic to pass the correct values.

Should nox stay this clean way?

Maybe some more configurable?

include_outer_env: Literal["all", "recommended", "none"]

while recommended will pass a similar list of environment variables like in tox.

e.g. on my setup I need to set HOME again, otherwise it wouldn't find my .netrc with the credentials for a private pypi repository.

henryiii commented 1 week ago

This is a separate issue (nox isn't even setting its own variables when include_outer_env is false, like VIRTUAL_ENV). But not a bad (separate) idea.