Skip to content

.env loading silently fails under common scenarios #307

Closed
@xlevus

Description

@xlevus

With the following test:

## example_test.py

import os

def test_potato():
  assert os.getenv("POTATO") == "potato"

def test_cabbage():
  assert os.getenv("CABBAGE") == "cabbage"
## BUILD
python_tests(extra_env_vars=["POTATO"])

This .env file works when running pants test ::

POTATO=potato
CABBAGE=cabbage

So does:

POTATO=potato
CABBAGE=cabbage
PYTHONPATH="/foo/bar:$PYTHONPATH"

But the following does not, and does not warn you there was a problem loading the env file.

CABBAGE=cabbage
PYTHONPATH="/foo/bar:$PYTHONPATH"
POTATO=potato

This is particularly troublesome, as adding PYTHONPATH="...:$PYTHONPATH" to your .env file is recommended to get vscode integration working in the documentation: https://www.pantsbuild.org/docs/setting-up-an-ide#first-party-sources

This seems to be the case for both Pants 2.16 and 2.17 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions