I have a problem using `extra_env_vars` for tests ...
# general
m
I have a problem using
extra_env_vars
for tests running in a docker_environment. First a quick description of my setup. The test ist located in
\path\to\test
and has a BUILD file:
Copy code
python_tests(
    name="tests",
    dependencies=[
        "some/dependency.py"
    ],
    extra_env_vars=env_vars_test(),
    environment="qgis_docker",
    xdist_concurrency=0,
)
The
env_vars_test
are defined in the
macros.py
, i.e.:
Copy code
def env_vars_test_django(**kwargs):  # noqa: ANN201, D103, ARG001
    envs = [
        'TILES_BUCKET=tiles-bucket',
        'TILES_URL=tiles.nefino.local',
        'SHAPEFILES_BUCKET=shapefiles-bucket',
        'PEL_PDF_EXPORTS_BUCKET=pel-bucket',
        'GLOBALWINDATLAS_BUCKET=globalwindatlas-bucket',
        'GLOBALWINDATLAS_V3_BUCKET=globalwindatlas-v3-bucket',
        'EARTHDATA_BUCKET_TRANSFORMED=earthdata-transformed-bucket',
        'EARTHDATA_BUCKET_ORIG=earthdata-bucket',
        ...
    ]
    return envs
In the BUILD file in
\path
I am defining an environment
Copy code
...
docker_environment(
    name="local_qgis",
    platform="linux_x86_64",
    image="qgis/qgis:3.34.7-bookworm",
)
...
Whicht gets the name in the pants.toml Now when I run the test I have the problem that not all Environment variables are set but it gets cut off at some variable, in my case it was a URL which was set as `SOME_URL=https" and all the rest and most other variables are missing. @wide-midnight-78598 do you maybe have an idea what happened?
w
What does
pants peek THE_TARGET_NAME give?
And just confirming that the docker_environment name matches the expected one in the tests?
m
@wide-midnight-78598 I will have a look at it tomorrow, but the docker_environment is correct. The test actually starts and reaches the os.environ() statement that I used to check the environment variables which are partially present. Unfortunately, I need all of them.
w
I think peek should show what is being passed into the environment. This error rings a bell, but I can’t recall the solution offhand. As in, whether there was an issue escaping env vars, or if they needed to be passed in a different way, etc
m
pants peek shows the full list of extra_env_vars, amongst a lot of others:
While printing the envs inside the test file gives me:
You can clearly see that the Novu Domain env gets cut off and in addition almost all other envs which are present in the output of pants peek are mussing. Any ideas @wide-midnight-78598?
w
I ran into something somewhere at some point in the past, where I made the hypothesis that slashes weren’t treated correctly during one of the env var translations. Or it was that some env vars needed to be re-escaped (we have so many places where you can inject env vars, and I hadn’t audited all the places where it could happen). I also can’t recall whether env vars returned from macros are escaped differently than env vars injected from BUILD files. @curved-television-6568 @happy-kitchen-89482 Have you run into something similar?
c
No, I don't recognize this.. 🤔
h
Me neither
w
Interesting, I guess it was just me 🤷 I’ll try digging to see where I ran into it, because this issue was “a thing” in the past, but maybe I just chalked it up to me misusing an API
@miniature-apartment-8295 Just want to confirm - looking into this, and since 2.19, it looks like pytest output gets stripped weirdly (maybe due to the str to bytes change, or the strutil "simplifier" we use - but to dig deeper, are these errors causing test-time failures? At the most basic level, I think the stdout needs to get fixed - but my tests using said env vars (in the simplest case) still work. If yours are failing as a result of this, then I think I'd need to look deeper at the interaction with environments/env vars/etc