<#18212 Inconsistent behaviour of test_extra_env_v...
# github-notifications
c
#18212 Inconsistent behaviour of test_extra_env_vars with docker environments Issue created by psontag Describe the bug I have configured the following env vars: In the pants.toml
Copy code
[test]
extra_env_vars = [
  "ENV_TOML=toml",
  "ENV_ALL=toml"
]
In the docker_environment
Copy code
docker_environment(
    name="dev_docker",
    platform="linux_x86_64",
    image="python:3.10.4-slim-bullseye",
    python_bootstrap_search_path=["<PATH>"],
    test_extra_env_vars=[
        "ENV_DOCKER=docker",
        "ENV_ALL=docker"
    ],
)
In the test target
Copy code
python_tests(
    environment="dev",
    extra_env_vars=[
        "ENV_TARGET=target",
        "ENV_ALL=target"
    ],
 )
My assumption would be that the following test passes when executed in the docker_environment:
Copy code
import os

def test_env_var():
    envs = {k: v for k,v in os.environ.items() if k.startswith('ENV_')}
    assert envs["ENV_TARGET"] == 'target'
    assert envs["ENV_ALL"] == 'target'

    assert envs["ENV_TOML"] == 'toml'
    assert envs["ENV_DOCKER"] == 'docker'
But I get the following errors:
Copy code
āžœ pants test tests/python/hello_world/messages/test_env_vars.py         
11:52:25.24 [ERROR] Completed: Run Pytest - (environment:dev, tests/python/hello_world/messages/test_env_vars.py) - failed (exit code 1).
============================= test session starts ==============================
platform linux -- Python 3.10.4, pytest-7.0.1, pluggy-1.0.0
rootdir: /pants-sandbox/pants-sandbox-uh2dCY
plugins: cov-3.0.0, forked-1.4.0, xdist-2.5.0
collected 1 item

tests/python/hello_world/messages/test_env_vars.py F                     [100%]

=================================== FAILURES ===================================
_________________________________ test_env_var _________________________________

    def test_env_var():
        envs = {k: v for k,v in os.environ.items() if k.startswith('ENV_')}
        assert envs["ENV_TARGET"] == 'target'
        assert envs["ENV_ALL"] == 'target'
    
>       assert envs["ENV_TOML"] == 'toml'
E       KeyError: 'ENV_TOML'
When I run the same test with the
--debug
flag I get a different error:
Copy code
āžœ pants test --debug tests/python/hello_world/messages/test_env_vars.py 
========================================== test session starts ==========================================
platform darwin -- Python 3.10.9, pytest-7.0.1, pluggy-1.0.0
rootdir: /private/var/folders/8b/0w6lmjjx7fsdm_6hhcrjfdfw0000gq/T/pants-sandbox-0SBEZ4
plugins: xdist-2.5.0, forked-1.4.0, cov-3.0.0
collected 1 item                                                                                        

tests/python/hello_world/messages/test_env_vars.py F                                              [100%]

=============================================== FAILURES ================================================
_____________________________________________ test_env_var ______________________________________________

    def test_env_var():
        envs = {k: v for k,v in os.environ.items() if k.startswith('ENV_')}
        assert envs["ENV_TARGET"] == 'target'
        assert envs["ENV_ALL"] == 'target'
    
        assert envs["ENV_TOML"] == 'toml'
>       assert envs["ENV_DOCKER"] == 'docker'
E       KeyError: 'ENV_DOCKER'
How is pants supposed to handle the env vars that are configured on the different levels? Are the lists supposed to be merged together or do should they be completely be replaced by the deepest configuration? Pants version 2.16.0.dev5, we are using the new scie-pants binary in version 0.3.2 OS MacOS Additional info I have created a reproducible example here https://github.com/psontag/pexample/tree/pants-env-vars pantsbuild/pants