https://pantsbuild.org/ logo
#general
Title
# general
b

brainy-solstice-27042

08/10/2022, 11:08 PM
I have a team member trying to access some environment variables within pytest code but we're unable to find the environment variables inside of the sandbox that 1.30 operates in. Is there a way to do something like
export PANTS_PYTEST_VAR1=test
and have the python code see that env var?
I see that 2.12 added some neat functionality which is a goal to upgrade to, but hoping there's a simple solution for 1.30 while we work through the upgrade to 2.12
e

enough-analyst-54434

08/10/2022, 11:36 PM
It looks like the option is
--test-extra-env-vars
(Or pants.toml it with
[test] extra_env_vars = [ ... ]
): https://github.com/pantsbuild/pants/blob/674df55a3dda870e78997965e617993b9d10d2eb/src/python/pants/core/goals/test.py#L195-L244
That's if using v2 rules, The v1 handling should just let env vars be read without any configuration.
b

brainy-solstice-27042

08/10/2022, 11:37 PM
this would be using v2
e

enough-analyst-54434

08/10/2022, 11:38 PM
Ok, that should do it then. And it looks like that's still the same setting in modern Pants 2.x.
b

brainy-solstice-27042

08/10/2022, 11:39 PM
I tried
./pants test --test-extra-env-vars VAR=v target::test
and pants told me that
--extra-env-vars
was not recognized.
e

enough-analyst-54434

08/10/2022, 11:40 PM
How about
./pants test --extra-env-vars VAR=v target::test
?
Ah, right. You need
=
😕
./pants test --extra-env-vars=VAR=v target::test
All pants flags unfortunately need
=
b

brainy-solstice-27042

08/10/2022, 11:43 PM
Oddly enough this is the help advanced menu
I would've expected it to list the global options too
e

enough-analyst-54434

08/10/2022, 11:43 PM
./pants --v2
right? You said you were using
--v2
?
b

brainy-solstice-27042

08/10/2022, 11:44 PM
Yeah, I have v1 disabled in the pants.toml file
e

enough-analyst-54434

08/10/2022, 11:44 PM
What is the exact Pants version?
b

brainy-solstice-27042

08/10/2022, 11:44 PM
1.30.0
e

enough-analyst-54434

08/10/2022, 11:45 PM
Try 1.30.4 or 1.30.5rc1.
Those are 2 latest 1.30.x
The code I linked was 1.30.x HEAD.
Looks like backported to 1.30.2rc0 (9/23/2020)
b

brainy-solstice-27042

08/10/2022, 11:47 PM
Oh gotcha, i'm trying .4 right now to see if that works better
Yeah, .4 looks like it will have that extra arg like you mentioned. I'll give it a go!
Sweet, that let me pass through the a dummy env var, I can easily add what I actually need from there. Thanks!
4 Views