Skip to content

Invalid environment assignments abort pytest with a traceback #344

Closed

Description

@gaborbernat

A name that the OS rejects aborts pytest before collection. The traceback ends in os.environ and gives no indication which entry to correct.

Affected code

Configuration handling at ac5583c

Mechanism

The native TOML parser accepts quoted keys. The assignment passes the key and value to os.environ without handling an OS rejection. The dotenv assignment has the same behavior. Reference

Reproduction

Run at ac5583cb5181 with pytest 9.2.0 in an empty directory on Linux.

printf '[tool.pytest_env]\n"BAD=NAME" = "example"\n' > pyproject.toml
pytest --collect-only -q

Observed output:

ValueError: illegal environment variable name

Report a pytest usage error identifying the entry.

Impact

Easy to reproduce. Exposure is niche because it requires a malformed assignment.

Credits

OSS Scanner report ANT-2026-6E5CMK4Q.

Activity

  1. added
    bug
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions