Python in Visual Studio Code – February 2019 Release

Dan Taylor

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!

Test Explorer

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 for the ability to run code selections without needing to define code cells. With this update, you can now send any code line/selection to run in the Python Interactive window using command “Python: Run Selection/Line in Python Interactive window”.

You can also use the shortcut key Shift+Enter by changing the python.dataScience.sendSelectionToInteractiveWindow setting to use the Python Interactive window instead of the default terminal.

Other Changes and Enhancements

We have also added small enhancements and fixed issues requested by users that should improve your experience working with Python in Visual Studio Code. The full list of improvements is listed in our changelog; some notable changes include:

  • Add support for multi root workspaces with the new language server. (#3008)
  • Added Dutch translation (thanks Robin Martijn with the feedback of Michael van Tellingen) (#4186)
  • Support simple variable substitution in .env (#3275)
  • Allow “Run Cell” code lenses on non-local files. (#3995)
  • Strip comments before sending to shell command and multiline Jupyter magics work correctly. (#4064)
  • Support launch configs for debugging tests. (#332)

Be sure to download the Python extension for Visual Studio Code now to try out the above improvements. If you run into any problems, please file an issue on the Python VS Code GitHub page.



Discussion is closed.

Feedback usabilla icon