Enable per test output correlation for pytest #22594
Labels
area-testing
feature-request
Request for new features or functionality
needs PR
Ready to be worked on
A request was made in an earlier issue for this type of feature add, before I thought it was not possible given the configuration but following help from pytest contributors it should work. What will now happen is, based on pytest arguments the user controls the output (including stdout, stderr and logging) will be captured and returned in the error popup box inline and the testResult panel for each test. Error popup is only applicable for tests which fail, the panel will display output from either both types. All output will now be correlated with each test unless configured otherwise by the user.
Steps for Implementation:
def pytest_report_teststatus(report, config):
report.capstdout
,report.caplog
andreport.capstderr
message
attribute of the Test Outcome object which is converted to json and sent to the extensionmessage
attribute should be designed to allow for distinction between the different types of output since themessage
attribute is of type string this will be done on the python sidemessage
attribute will be read by the extension, it is then displayed dependent on test outcomemessage
isn't empty and if it isn't then present that message to the user. My plan is this message will display in the testResult panel similar to the failed tests.User Configurability
Importantly in this design is the ability for user control of the output. There are two main pytest parameters that give the user control that our extension must respect:
-s
or--capture=no
: When you use this option, pytest does not capture the output of the tests and instead prints to console (default value is capture is on)-rA
or--show-capture=all
: This parameter has many "levels" where the user can chose passed tests, failed tests, skipped tests etc to have their capture shown to the user.-s
-s
flag, pytest will not capture any output and so ourmessage
attribute will have a stack trace in the case of failure and any logging. the-s
flag does not impact logging.-rA
message
will respect this setting level. The only additional consideration is that if amessage
value is empty (which might happen if the test passes and therA
flag is off) we do not want to display a blank message in the testResult panel and therefore a check needs to be in place to confirm if it is empty.Test Case Examples
as well as the arguments
-s
and-rA
tried in different combinationsExpected Behavior Based on Arguments
when a test fails, the value of message will be:
-s
-rA
when a test passes, the value of message will be:
-s
-rA
Visuals
test failure popup:
testResult panel:
The text was updated successfully, but these errors were encountered: