Python in Visual Studio Code – February 2019 Release
We are pleased to announce that the February 2019 release of the Python Extension for Visual Studio Code is now available. You can download the Python extension from the Visual Studio Marketplace, or install it directly from the extension gallery in Visual Studio Code. You can learn more about Python support in Visual Studio Code in the documentation.
In this release we have closed a total of 40 issues, including a built-in Test Explorer, validation of breakpoint targets when debugging, and the ability to run any code selection in the Python Interactive window.
Keep on reading to learn more!
This release includes the ability to visualize, navigate and run unit tests through a test explorer, a feature that is commonly requested by our users. To access it, you can run the command Python: Discover Unit Tests from the Command Palette (View -> Command Palette). If the unit test feature is disabled or no test framework is configured in the settings.json file, you’ll be prompted to select a framework and configure it. Once tests are discovered, the Test Explorer icon will appear on the Activity Bar.
The tests files and suites are displayed in a tree view with their corresponding test methods, and can be expanded or collapsed accordingly.
Through the buttons located on the top right of the test explorer, you can run all displayed tests, run the failed ones (only shown if there’s a failing test), update/refresh the tree view, debug all tests and open the output window for the Python Test Log:
You can also run and debug a single test method or all the tests from an entire file or suite through the buttons that appear when you select or hover over an item in the tree view, as well as navigate to the line of each test:
The test framework can also be chosen and configured by running the newly added command Python: Configure Unit Tests from the Command Palette. As a reminder, the Python extension supports unit testing with Python’s built-in unittest framework as well as pytest. Nose is also supported, although the framework itself is in maintenance mode.
Validated breakpoints when debugging
This release also includes an enhancement to the debugger: validation of breakpoints targets. If a breakpoint is set on a line where breakpoints are invalid (e.g. blank lines, pass statement, lines in the middle of a multi-line statement), then it’s automatically moved to the nearest preceeding valid line:
This way the breakpoints added are ensured to be hit. Previously the debugger would continue running past invalid breakpoints, causing confusion or wasted time.
Run code selection in the Python Interactive window
Since adding the Python Interactive window in the October release, one of the top-requested features has been