Hi, I am running some python tests and it seems li...
# general
h
Hi, I am running some python tests and it seems like
test
goal doesn't output,
print
statements but only outputs
logging
outputs
Copy code
# temp_test.py

from loguru import logger

def test_simple():
    print("Hello")
    print(f"Hello 2")
    logger.info("This is a test message")
    assert True
when I run
Copy code
pants --test-output=all --pytest-args="-s -vv" test temp_test.py
I correctly see the output of
logger
in console, but not of
print
statements
Copy code
======================= 1 passed, 2 warnings in 0.67s =========================

2023-11-16 09:36:30.990 | INFO     | temp_test:test_simple:7 - This is a test message
If i explicitly run with
pytest
i can see the print statement output. Am i missing any configuration or could this be a bug ?
👍 1
g
Are you maybe using
-s
when
-rP
would work better?
-s
disables capture completely, so it'll appear in the "test progress" output which makes it hard to see sometimes.
-rP
puts it at the end which is generally easier to spot.
💡 1
h
Tried with
-rP
as well. The issue i am seeing is output of
print
isn't rendered on console, but of
logger
is rendered. Tom, what did you use to print
Here I am
. Did you use
print
statement or some
logger
? What version of pants are you using? I am using
2.18.0
g
I put the whole repro here: https://github.com/tgolsson/pants-repros/tree/main/testing-missing-output Pants 2.18, pytest 7.
h
Thanks
g
We have this issue which I've caused but never been able to reproduce. It's hard to tell if it's the same though. https://github.com/pantsbuild/pants/issues/20171 .
l
I tested it on Pants 2.15.2 and it works as expected:
Copy code
==================================== PASSES ====================================
_________________________________ test_simple __________________________________
----------------------------- Captured stdout call -----------------------------
Hello
Hello 2
----------------------------- Captured stderr call -----------------------------
2023-11-16 23:16:38.852 | INFO     | test:test_simple:11 - This is a test message
Bear in mind that
loguru
by default outputs to
stderr
(see this section).
The logger is pre-configured for convenience with a default handler which writes messages to
sys.stderr
.
So something is intercepting your
stdout
. Maybe try this trick?
👍 1