Another related question, if I configure my enviro...
# general
p
Another related question, if I configure my environments like that:
Copy code
local_environment(
    name="linux_compatible",
    compatible_platforms=["linux_x86_64"],
    fallback_environment="test_run_env",
)

docker_environment(
    name="test_run_env",
    image="test-run-env:v1",
)
this means that on linux mentioned component tests will on host, but on MacOS they will run in container. This means that
SERVICE_HOST
variable set in component tests needs to vary, depending on the environment (local, or fallback one)
Copy code
python_tests(
    name="tests",
    environment="linux_compatible",
    extra_env_vars=[
        "SERVICE_HOST=localhost/host.docker.internal",
        ...
    ],
)
Is there a way of achieving that without defining
test_extra_env_vars
in
docker_environment
to override
SERVICE_HOST
? That environment is shared between various tests for different services, I wanted to keep only one local+docker env setup to keep things simple, but it looks like I'd have to define separate environment setup for each service that I want to test?
ok, I think that's actually not possible... I wanted a setup like this (it's a monorepo built with pants):
Copy code
common/
   ...
services/
    service1/
        tests/
            BUILD #1
services/
    service2/
        tests/
            BUILD #2
pants.toml
with BUILD 1:
Copy code
python_tests(
    extra_env_vars=[
        "SERVICE1_HOST=localhost",
    ]
)

local_environment(
    name="service1_linux",
    compatible_platforms=["linux_x86_64"],
    fallback_environment="service1_docker",
)

docker_environment(
    name="service1_docker",
    image="...",
    test_extra_env_vars=[
        "SERVICE1=host.docker.internal",
    ]   
)
and BUILD2
Copy code
python_tests(
    extra_env_vars=[
        "SERVICE2_HOST=localhost",
    ]
)

local_environment(
    name="service2_linux",
    compatible_platforms=["linux_x86_64"],
    fallback_environment="service2_docker",
)

docker_environment(
    name="service2_docker",
    image="...",
    test_extra_env_vars=[
        "SERVICE2=host.docker.internal",
    ]   
)
but pants complain about multiple local environments and that's ambiguous to pick which one to run?...
OK I've ended up using
Copy code
python_tests(
    extra_env_vars=[
        "SERVICE1_HOST=" + env("LOCALHOST_NAME"),
    ]
)
and running pants via bash script that populates LOCALHOST_NAME to either "localhost" or "host.docker.internal" on mac...
I'd much rather have this variable defined in local/docker environment somehow, but it looks like env() always reads from host (which makes sense)