I'm trying to increase the log level to output deb...
# general
m
I'm trying to increase the log level to output debug messages when running pytests using pants. I want to pass the
LOGLEVEL
environment variable to the test execution environment so what I did is modify the
python_tests
target to pass it:
Copy code
python_tests(
    dependencies=[
        "backend#asyncpg",
    ],
    extra_env_vars=(
        "LOGLEVEL",
    ),
)
and then run it like this:
Copy code
LOGLEVEL=debug pants --keep-sandboxes=always --level=debug test tests/api/test_tasks.py:tests
Still, the variable is not passed and I don't get it what I do wrong. Anyone has some tips that might help me figure this out?
I'm also printing the environment to double check
b
Sorry for the trouble! A good way to debug these issues is to confirm what process pants is executing in the sandbox: https://www.pantsbuild.org/2.21/docs/using-pants/troubleshooting-common-issues#debug-tip-inspect-the-sandbox-with---keep-sandboxes Hopefully that'll confirm whether
LOGLEVEL
exists in the
__run.sh
script, to indicate whether it's a pants problem (doesn't exist), or maybe it's peculiar/unexpected behaviour from the process being executed (does exist but is ignored)
đź‘€ 1
m
Nope
Copy code
❯ more /private/var/folders/v7/lj0l76_974z62kvrtzy7x5xw0000gn/T/pants-sandbox-o8dZQw/__run.sh
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /private/var/folders/v7/lj0l76_974z62kvrtzy7x5xw0000gn/T/pants-sandbox-o8dZQw
env -i PEX_EXTRA_SYS_PATH=backend ./pytest_runner.pex_pex_shim.sh $'--color=yes' $'--junit-xml=backend.tests.api.test_tasks.py.tests.xml' -o $'junit_family=xunit2' backend/tests/api/test_tasks.py
b
You might need to include
LOGLEVEL
in the
extra_env_vars
argument for the
test
goal: https://www.pantsbuild.org/2.21/reference/goals/test#extra_env_vars
Copy code
[test]
use_coverage = true
extra_env_vars=[
  "REDIS_HOST=localhost",
  "CI",q
]
b
The target field is documented as extending that one, so it is a bit weird… Can you create a reduced/standalone reproducer?
m
> Can you create a reduced/standalone reproducer? Will try to. > You might need to include
LOGLEVEL
in the
extra_env_vars
argument for the
test
goal After adding it to the
pants test
call as an argument (
--extra-env-vars="['LOGLEVEL']"
) it now does successfully pass it and if I execute the
__run.sh
from the sandbox I do see it logging but I still don't see it if I run it through
pants
:
LOGLEVEL=debug pants --keep-sandboxes=always --level=info test --extra-env-vars="['LOGLEVEL']" --force tests/some_test.py:tests -- --log-cli-level=DEBUG
and this is how
__run.sh
looks like:
Copy code
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /private/var/folders/v7/lj0l76_974z62kvrtzy7x5xw0000gn/T/pants-sandbox-DZDyqY
env -i LOGLEVEL=debug PEX_EXTRA_SYS_PATH=backend ./pytest_runner.pex_pex_shim.sh $'--log-cli-level=DEBUG' $'--color=yes' $'--junit-xml=backend.tests.some_test.py.tests.xml' -o $'junit_family=xunit2' backend/tests/some_test.py
b
Hm, weird that the
test
version of this option seems to work better. If we can get a reproducer, we might be able to confirm if there's a bug or not. Pants will still capture and hide the output of passing tests. Using the
test --debug ...
option too stops pants from doing this, by running each test sequentially