Skip to content
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

Logging in subtests is not displayed unless the parent test fails #87

Closed
rhoban13 opened this issue Apr 21, 2023 · 0 comments · Fixed by #91
Closed

Logging in subtests is not displayed unless the parent test fails #87

rhoban13 opened this issue Apr 21, 2023 · 0 comments · Fixed by #91

Comments

@rhoban13
Copy link
Contributor

rhoban13 commented Apr 21, 2023

Logging in subtests is not displayed unless the parent test fails. Contrast with stdout is displayed for just the failing subtest.

Minimal example:

import logging


def test_logging_in_subtests(subtests):
    logging.info("before")

    with subtests.test("sub1"):
        print("sub1 stdout")
        logging.info("sub1 logging")

    with subtests.test("sub2"):
        print("sub2 stdout")
        logging.info("sub2 logging")
        assert False

Running python3.8 -m pytest test_pytest.py --log-level=INFO stdout is output but not logs

...
------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------
sub2 stdout
================================================================================================ short test summary info ================================================================================================
SUBFAIL test_pytest.py::test_logging_in_subtests - assert False

If instead the parent test fails, logs are output from both failing & succeeding subtests. For example

import logging


def test_logging_in_subtests(subtests):
    logging.info("before")

    with subtests.test("sub1"):
        print("sub1 stdout")
        logging.info("sub1 logging")

    with subtests.test("sub2"):
        print("sub2 stdout")
        logging.info("sub2 logging")
        assert False

    assert False

$ python3.8 -m pytest test_pytest.py --log-level=INFO now produces

------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------
sub2 stdout
_______________________________________________________________________________________________ test_logging_in_subtests ________________________________________________________________________________________________
...<stack trace> ...
--------------------------------------------------------------------------------------------------- Captured log call ---------------------------------------------------------------------------------------------------
INFO     root:test_pytest.py:5 before
INFO     root:test_pytest.py:9 sub1 logging
INFO     root:test_pytest.py:13 sub2 logging
================================================================================================ short test summary info ================================================================================================
SUBFAIL test_pytest.py::test_logging_in_subtests - assert False
FAILED test_pytest.py::test_logging_in_subtests - assert False

Can/should logging be displayed with a per subtest granularity similar to stdout?

nicoddemus added a commit that referenced this issue May 15, 2023
Fix #87 

---------

Co-authored-by: Bruno Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant