Is there a way to make `__defaults__` propagate to...
# general
a
Is there a way to make
__defaults__
propagate to all subdirectories? I have my tests organized in a manner like this:
Copy code
tests/
   module_1/
   module_2/
   ...
   module_n/
   BUILD
All of these modules share the same
extra_env_vars
and I wanted to include a
BUILD
at the
tests/
level, but the environment variables are not injected into the tests if I do this. The contents of the BUILD file is:
Copy code
__defaults__(
    all=dict(
        extra_env_vars=[
          "SOME_VAR=some_value",
          ...
        ]
    )
)
Using
pants peek
it just doesn't seem like
extra_env_vars
is being passed along to any of the tests residing in the directories above the build-file.
f
Dumb question: Are there
BUILD
files in the
module_N
directories with
python_tests
targets?
a
Yep, there are. There are also BUILD files with
__defaults__
in the subdirectories, but using
extend=True
on these does not affect the outcome.
f
Can you share a reproduction? Do any of the test targets inthe
BUILD
files in the
module_N
directories set
extra_env_vars
directly?
I had Claude try and produce a reproduction and from what I can see, the issue could be that the values of
extra_env_vars
are not being merged together but are instead ovewritten. I'm curious if that matches what you are seeing.
I don't believe there is any special merge strategy other then overwriting. So merging default together would be merging separate keys, not the same key.
you would need to do something like:
Copy code
__defaults__(
    extend=True,
    all=dict(
        extra_env_vars=list(python_test.extra_env_vars.default) + [
            "MODULE2_VAR=module2_specific",
        ]
    )
)

python_tests(
    name="tests",
)