Skip to content

pytest results in VSCode should show logging. #21781

Closed as not planned
Closed as not planned

Description

@PhilipMay

I have a simple test:

import logging
LOGGER = logging.getLogger(__name__)
def test():
    a = 888
    LOGGER.info(">>>>>> Test1 <<<<<<<<<<<<< %s", a)
    assert False

I configuted pytest so it is logging at info level.
See pyproject.toml:

[tool.pytest.ini_options]
log_cli_level="INFO"

When I execute the test with pytest tests it shows this:


tests/test_log.py F                                                                                                                       [100%]

=================================================================== FAILURES ====================================================================
_____________________________________________________________________ test ______________________________________________________________________

    def test():
        a = 888
        LOGGER.info(">>>>>> Test1 <<<<<<<<<<<<< %s", a)
>       assert False
E       assert False

tests/test_log.py:9: AssertionError
--------------------------------------------------------------- Captured log call ---------------------------------------------------------------
INFO     tests.test_log:test_log.py:8 >>>>>> Test1 <<<<<<<<<<<<< 888
============================================================ short test summary info ============================================================
FAILED tests/test_log.py::test - assert False
=============================================================== 1 failed in 0.04s ===============================================================

Please not that it also shows the log output - which is this:
INFO tests.test_log:test_log.py:8 >>>>>> Test1 <<<<<<<<<<<<< 888.

I also want to see this logging output on the VSCode snippet that shows up at failed test functions. See screenshot:

But it is missing here:
image

Can you add the log output?

Activity

  1. changed the title [-]pytest results should show logging.[/-] [+]pytest results in VSCode should show logging.[/+] on Aug 7, 2023
  2. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    feature-requestRequest for new features or functionality
    on Aug 8, 2023
  3. eleanorjboyd commented on Aug 9, 2023

    @eleanorjboyd

    Thank you for your issue report. We are looking into this now! In the meantime, you are likely on the new testing rewrite and this is why you saw a change in behavior. You can opt out of the rewrite as I get this fix in by setting this in your user settings: "python.experiments.optOutFrom": ["pythonTestAdapter"],. If this doesn't work let me know as this will mean it is a different issue. Thank you and I will send updates in this thread as I get a fix in.

  4. eleanorjboyd commented on Aug 17, 2023

    @eleanorjboyd

    Hi! After investigating this further I believe that what you are seeing is actually the desired behavior. If you run this from the command line you see the output in the screenshot below (as you included). As you can see pytest actually splits it into sections, the failure section which lists the test that was run which has the error and any stack trace then another section for "Captured Log Output" which is where you will see the logging message. The logs are not split by test as known to pytest. Therefore when pytest is done, the per test message it produces is what is displayed in the pop up since that is all the information pytest provides.

    image
  5. added and removed
    bugIssue identified by VS Code Team member as probable bug
    info-neededIssue requires more information from poster
    triage-neededNeeds assignment to the proper sub-team
    on Aug 17, 2023
  6. eleanorjboyd commented on Aug 17, 2023

    @eleanorjboyd

    I was incorrect this can be done- reopening to investigate. Sorry about that

  7. eleanorjboyd commented on Oct 4, 2023

    @eleanorjboyd

    Hello I have spent a while digging into this issue specifically because of #21861. In my investigation, the output (which is where logging is sent) is separate from the stack trace and message that pytest saves for failed tests which is what is shown per test. Since this is just output, and there is no way good way to capture the output perfectly per test run while still supplying the logging I don't think it is realistic for us to do this at this time. If this idea gets more traction I can rethink but design-wise pytest doesn't split output by test so with the goal of replicating pytest in our extension this is not something we necessarily want to provide.

  8. locked as resolved and limited conversation to collaborators on Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testinginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions