Skip to content

New Method for Output Handling in Python Testing

Eleanor Boyd edited this page Sep 25, 2023 · 5 revisions

What Changed?

As part of the overhaul of the extension's testing infrastructure, the testing output has also undergone a redesign to enhance the compatibility with VS Code tools and its interface. Previously, all testing output, both the output generated during test discovery and test execution, was printed into the Python Test Logs output channel, which was located under the Output tab in the Workbench (please refer to the images below for visual reference to the different UI elements discussed here). Now, the testing discovery output will be located in the Python output channel, while the output from test execution will be found in the Test Results panel within the Workbench. This modification reduces the number of places that users need to consult while running and debugging their tests. Discovery output logging will be captured at the trace level, while errors occurring during discovery will remain at the error log level. Output for execution is managed by the testing libraries, namely unittest or pytest, so any adjustments to log levels or verbosity should be made within these libraries. On the Test Result panel, each test now has its own item nested under the general run call menu item. Just as before, clicking on the nested test item will display the message specific to that particular test, a feature that only applies to failed tests. To access all the output from the entire test run, you can either right-click on the parent test menu item or use the console icon next to it. Output will still appear in "Python Test Logs" for now as we complete the transition to these new output locations.

The highlighted output channel will be removed in a month after the transitional period is over: Screenshot 2023-09-25 at 12 08 40 PM

All discovery output will output in the Python log like so: Screenshot 2023-09-25 at 12 06 34 PM

All run output will be in the Test Results Panel: Screenshot 2023-09-25 at 12 09 10 PM Individual run items, shown clicked below, will have error messages and stack traces. Screenshot 2023-09-25 at 12 09 19 PM

Overall output returned per run and will be displayed as part of the header item. This output will appear after the run but can also be accessed via the terminal icon and the right-click menu.

Screenshot 2023-09-25 at 12 09 32 PM Screenshot 2023-09-25 at 12 09 25 PM

Why Was This Change Implemented?

In the previous design of testing within the extension, all output was read and parsed to populate the testing user interface, such as the Test Result panel and the Test Explorer. In the rewrite, this is no longer necessary because the information required to populate the user interface is communicated over a socket. With this change, the extension no longer needs to control the output for information digestion, and we are now returning full control to the user regarding the appearance of their output. This increased flexibility enables information to be presented in line with VS Code's design principles, keeping Python output consolidated within a single channel and Python testing output integrated with all test results. Additionally, this change allows the use of the --color=yes argument to color output of as pytest does in the command line normally.

As always, you can file an issue or post a Q&A with any concerns regarding this design change, happy coding!

Clone this wiki locally