acoustic-library-86413
11/17/2023, 11:38 AMos.environ["VAR_NAME"] = "some value"
. This isn't reflected when the test is ran, even when VAR_NAME
is included without a value in extra_env_vars
in the BUILD file for the tests. Is this intended behavior?late-advantage-75311
11/17/2023, 11:40 AMos.environ["VAR_NAME"] = "some value"
occurring? Could you provide some more details? If you are running a python process and it sets the os.environ and then reads it later, I can't imagine that pants can get in the way of that.acoustic-library-86413
11/17/2023, 11:44 AMdef test_example():
os.environ["VAR_NAME"] = "<https://test.com>"
settings = Settings()
assert settings.enable_sink is True
Here is the test. The build file looks like this:
python_tests(
name="tests",
extra_env_vars=[
"VAR_NAME",
]
)
acoustic-library-86413
11/17/2023, 11:44 AMlate-advantage-75311
11/17/2023, 11:48 AMdef test_example():
assert os.environ['VAR_NAME'] == 'good'
and you can run $ VAR_NAME=good pants test path/to/the/test.py
late-advantage-75311
11/17/2023, 11:48 AMSettings()
read the os.environ
?late-advantage-75311
11/17/2023, 11:49 AMacoustic-library-86413
11/17/2023, 11:50 AMSettings()
which internally calls pydantic_settings.BaseSettings
reads the environment variables 🙂acoustic-library-86413
11/17/2023, 11:50 AMlate-advantage-75311
11/17/2023, 11:50 AMlate-advantage-75311
11/17/2023, 11:51 AMlate-advantage-75311
11/17/2023, 11:51 AMlate-advantage-75311
11/17/2023, 11:58 AMacoustic-library-86413
11/17/2023, 12:05 PMsettings = Settings()
in the file I was importing from. This means that when I ran my test this would be run twice, the first time before my monkeypatch had a chance to take effect, and then again in my test, now with patched values.acoustic-library-86413
11/17/2023, 12:05 PMacoustic-library-86413
11/17/2023, 12:06 PMlate-advantage-75311
11/17/2023, 12:06 PM