Skip to content

The caplog fixture doesn't appear to work consistently #8977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
medley56 opened this issue Aug 5, 2021 · 2 comments
Closed

The caplog fixture doesn't appear to work consistently #8977

medley56 opened this issue Aug 5, 2021 · 2 comments
Labels
plugin: capture related to the capture builtin plugin plugin: logging related to the logging builtin plugin type: question general question, might be closed after 2 weeks of inactivity

Comments

@medley56
Copy link

medley56 commented Aug 5, 2021

Taking the example test from the caplog documentation:

def test_foo(caplog):
    logging.getLogger().info("boo %s", "arg")
    print(caplog.record_tuples)
    assert caplog.record_tuples == [("root", logging.INFO, "boo arg")]

I've created a test module in the directory tests/test_test_foo.py.

When I run pytest tests, it passes (along with the rest of my tests) but when I run pytest tests/test_test_foo.py it appears that the caplog object doesn't capture anything:

❯ pytest tests/test_test_foo.py
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 3.9.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/game1390/Workspace/Libera/libera_sdp
collected 1 item                                                                                                                                                                                         

tests/test_test_foo.py F                                                                                                                                                                           [100%]

================================================================================================ FAILURES ================================================================================================
________________________________________________________________________________________________ test_foo ________________________________________________________________________________________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x10bb77310>

    def test_foo(caplog):
        logging.getLogger().info("boo %s", "arg")
>       assert caplog.record_tuples == [("root", logging.INFO, "boo arg")]
E       AssertionError: assert [] == [('root', 20, 'boo arg')]
E         Right contains one more item: ('root', 20, 'boo arg')
E         Use -v to get the full diff

tests/test_test_foo.py:6: AssertionError
======================================================================================== short test summary info =========================================================================================
FAILED tests/test_test_foo.py::test_foo - AssertionError: assert [] == [('root', 20, 'boo arg')]
=========================================================================================== 1 failed in 0.11s ============================================================================================

If anything I would have expected the opposite behavior. i.e. failing in presence of my other tests but passing on its own. Is this a bug? I don't know. I'm probably doing something wrong but I've exhausted the documentation and stackoverflow so I felt I should bring the question here.

@Zac-HD Zac-HD added plugin: capture related to the capture builtin plugin type: question general question, might be closed after 2 weeks of inactivity labels Aug 6, 2021
@Zac-HD Zac-HD added the plugin: logging related to the logging builtin plugin label Nov 29, 2021
@Zac-HD
Copy link
Member

Zac-HD commented Nov 29, 2021

Closing this because it's well over our 14-day timeout for questions. Unfortunately I also don't know the answer 😢

@Zac-HD Zac-HD closed this as completed Nov 29, 2021
@pastorenuel
Copy link

Don't know if this helps anyone even though its closed already. But, I noticed that the line below was in the LOGGING configuration in my django project and removing it, fixed the error:
"root": {"handlers": ["console", "file"], "level": "DEBUG"},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: capture related to the capture builtin plugin plugin: logging related to the logging builtin plugin type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants