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

pytest results in VSCode should show logging. #21781

Closed
PhilipMay opened this issue Aug 7, 2023 · 4 comments
Closed

pytest results in VSCode should show logging. #21781

PhilipMay opened this issue Aug 7, 2023 · 4 comments
Assignees
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@PhilipMay
Copy link

PhilipMay commented Aug 7, 2023

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?

@PhilipMay PhilipMay added the feature-request Request for new features or functionality label Aug 7, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 7, 2023
@PhilipMay PhilipMay changed the title pytest results should show logging. pytest results in VSCode should show logging. Aug 7, 2023
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Aug 8, 2023
@eleanorjboyd
Copy link
Member

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.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Aug 9, 2023
@eleanorjboyd
Copy link
Member

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

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@eleanorjboyd eleanorjboyd added area-testing and removed bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels Aug 17, 2023
@eleanorjboyd
Copy link
Member

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

@eleanorjboyd eleanorjboyd reopened this Aug 17, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 17, 2023
@eleanorjboyd
Copy link
Member

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.

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Oct 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants