Are there known issues with the pytest capture log...
# general
s
Are there known issues with the pytest capture logs (caplog) fixture on pants?
1
c
none that I’m aware of at least.. what’re you experiencing?
c
I think this is something going on in your tests and/or application under test. Singleing out a troublesome test passes, but when run together with the other tests, it starts failing (it passes also without the propagate=True, so that’s not the issue here it would seem)
Copy code
================================================== test session starts ===================================================
platform darwin -- Python 3.7.13, pytest-7.0.1, pluggy-1.0.0 -- /Users/andreas.stenius/.cache/pants/named_caches/pex_root/venvs/s/578dffe4/venv/bin/python3.7
cachedir: .pytest_cache
rootdir: /private/var/folders/y2/6t5bbk554wv5h6w_qlgpcpnm0000gr/T/pants-sandbox-3dqcUX
plugins: xdist-2.5.0, forked-1.4.0, anyio-3.6.2, cov-3.0.0
collected 108 items / 100 deselected / 8 selected

tests/test_http.py::test_request_logging[HTTPProtocol0-/] PASSED                                                   [ 12%]
tests/test_http.py::test_request_logging[HTTPProtocol0-/?foo] PASSED                                               [ 25%]
tests/test_http.py::test_request_logging[HTTPProtocol0-/?foo=bar] PASSED                                           [ 37%]
tests/test_http.py::test_request_logging[HTTPProtocol0-/?foo=bar&baz=1] PASSED                                     [ 50%]
tests/test_http.py::test_request_logging[HTTPProtocol1-/] PASSED                                                   [ 62%]
tests/test_http.py::test_request_logging[HTTPProtocol1-/?foo] PASSED                                               [ 75%]
tests/test_http.py::test_request_logging[HTTPProtocol1-/?foo=bar] PASSED                                           [ 87%]
tests/test_http.py::test_request_logging[HTTPProtocol1-/?foo=bar&baz=1] PASSED                                     [100%]

=========================================== 8 passed, 100 deselected in 0.09s ============================================
Copy code
#@pytest.mark.skip(reason="Issue with capture logs fixture.")
@pytest.mark.anyio
@pytest.mark.parametrize("path", ["/", "/?foo", "/?foo=bar", "/?foo=bar&baz=1"])
async def test_request_logging(path, http_protocol, caplog):  # pragma: no cover
    get_request_with_query_string = b"\r\n".join(
        ["GET {} HTTP/1.1".format(path).encode("ascii"), b"Host: <http://example.org|example.org>", b"", b""]
    )
    #caplog.set_level(<http://logging.INFO|logging.INFO>)
    caplog.set_level(<http://logging.INFO|logging.INFO>, logger="uvicorn.access")
    #logging.getLogger("uvicorn.access").propagate = True
    assert logging.getLogger("uvicorn.access").propagate
    assert logging.getLogger("uvicorn").propagate
    
    app = Response("Hello, world", media_type="text/plain")
...
s
how do u run a single test btw?
c
./pants test <target> -- -k <testname pattern>
I used:
Copy code
./pants --loop test --debug tests/test_http.py -- -vv -k request_logging
the debug as I wanted to see all tests executed…
s
thank you 🙏
👍 1
fixed 🙌
🎉 2
thanks 😎
🏖️ 2