Skip to content

session.env contains None values #930

@pquentin

Description

@pquentin

Thank you for maintaining nox!

Current Behavior

The session.env dictionary contains the following variables set to None:

  • PIP_REQUIRE_VIRTUALENV
  • PIP_RESPECT_VIRTUALENV
  • UV_SYSTEM_PYTHON
  • __PYVENV_LAUNCHER__
  • CONDA_PREFIX

Additionally, it only contains two string values:

  • VIRTUAL_ENV
  • NOX_CURRENT_SESSION

It does not contain eg. PATH, which is #928. But since my symptoms are different, I opened a different issue.

As a result, when I pass env=session.env in a subprocess call, I get the following exception:

    env_list.append(k + b'=' + os.fsencode(v))
                               ~~~~~~~~~~~^^^
  File "<frozen os>", line 849, in fsencode
TypeError: expected str, bytes or os.PathLike object, not NoneType

Expected Behavior

I would expect session.env to 1/ actually contain the environment 2/ not contain any None values.

Steps To Reproduce

With this noxfile:

import nox

@nox.session()
def test(session):
    for k, v in session.env.items():
        print(k, v)
$ nox -s test
__PYVENV_LAUNCHER__ None
UV_SYSTEM_PYTHON None
PIP_REQUIRE_VIRTUALENV None
PIP_RESPECT_VIRTUALENV None
VIRTUAL_ENV /private/tmp/.nox/test
CONDA_PREFIX None
NOX_CURRENT_SESSION test

Environment

- OS: macOS 15.3
- Python: 3.13.1
- Nox: 2025.02.09

Anything else?

I have bisected this, and the culprit appears to be #874.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions