October 4th, 2024
heart2 reactions

Python in Visual Studio Code – October 2024 Release

Courtney Webster
Program Manager

We’re excited to announce the October 2024 release of thePython andJupyter extensions for Visual Studio Code!

This release includes the following announcements:

  • Run Python tests with coverage
  • Default Python problem matcher
  • Python language server mode

If you’re interested, you can check the full list of improvements in our changelogs for thePython,Jupyter andPylance extensions.

Run Python tests with coverage

You can now run Python tests with coverage in VS Code! Test coverage is a measure of how much of your code is covered by your tests, which can help you identify areas of your code that are not being fully tested.

Tip: Running Python tests with coverage is currently only supported when "python.experiments.optInto": ["pythonTestAdapter"] is added to your User settings.json.

To run tests with coverage enabled, select the coverage run icon in the Test Explorer or the “Run with coverage” option from any menu you normally trigger test runs from. The Python extension will run coverage using the pytest-cov plugin if you are using pytest, or with coverage.py for unittest.

Note: Before running tests with coverage, make sure to install the correct testing coverage package for your project.

Once the coverage run is complete, lines will be highlighted in the editor for line level coverage. Test coverage results will appear as a “Test Coverage” sub-tab in the Test Explorer, which you can also navigate to with Testing: Focus on Test Coverage View in Command Palette (F1)). On this panel you can view line coverage metrics for each file and folder in your workspace.

Gif showing Python tests running with coverage.

For more information on running Python tests with coverage, see ourPython test coverage documentation. For general information on test coverage, see VS Code’sTest Coverage documentation.

Default Python problem matcher

We are excited to announce support for one of ourlongest request features: there is now a default Python problem matcher! Aiming to simplifying issue tracking in your Python code and offering more contextual feedback, a problem matcher scans the task’s output for errors and warnings and displays them in the Problems panel, enhancing your development workflow. To integrate it, add"problemMatcher": "$python" to your tasks intask.json.

Below is an example of a task.json file that uses the default problem matcher for Python:

{    "version": "2.0.0",    "tasks": [        {            "label": "Run Python",            "type": "shell",            "command": "${command:python.interpreterPath}",            "args": [                "${file}"            ],            "problemMatcher": "$python"        }    ]}

For more information on tasks and problem matchers, visit VS Code’sTasks documentation.

Pylance language server mode

There’s a new settingpython.analysis.languageServerMode that enables you to choose between our current IntelliSense experience or a lightweight one that is optimized for performance. If you don’t require the full breadth of IntelliSense capabilities and prefer Pylance to be as resource-friendly as possible, you can setpython.analysis.languageServerMode tolight. Otherwise, to continue with the experience you have with Pylance today, you can leave out the setting entirely or explicitly set it todefault .

This new functionality overrides the default values of the following settings:

Settinglight modedefault mode
“python.analysis.exclude”[“**”][]
“python.analysis.useLibraryCodeForTypes”falsetrue
“python.analysis.enablePytestSupport”falsetrue
“python.analysis.indexing”falsetrue

The settings above can still be changed individually to override the default values.

Shell integration in Python terminal REPL

The Python extension now includes apython.terminal.shellIntegration.enabled setting to enable a better terminal experience on MacOS and Linux machines. When enabled, this setting runs aPYTHONSTARTUP script before you launch the Python REPL in the terminal (for example, by typing and enteringpython), allowing you to leverage terminal shell integrations such as command decorations, re-run command and run recent commands.

Gif show shell integration enabled in the 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 and Jupyter Notebooks in Visual Studio Code. Some notable changes include:

  • ExperimentalImplement Abstract Classes with Copilot Code Action available for GitHub Copilot users using Pylance. Enable by adding"python.analysis.aiCodeActions": {"implementAbstractClasses": true} in yourUser settings.json
  • Fixed duplicate Python executable code when sending code to the Terminal REPL by usingexecuteCommand rather thansendText for the activation command in@vscode#23929

We would also like to extend special thanks to this month’s contributors:

Try out these new improvements by downloading thePython extension and theJupyter extension from the Marketplace, or install them directly from the extensions view in Visual Studio Code (Ctrl + Shift + X or ⌘ + ⇧ + X). You can learn more aboutPython support in Visual Studio Code in the documentation. If you run into any problems or have suggestions,please file an issue on thePython VS Code GitHub page.

Category
Topics
Share

Author

Courtney Webster
Program Manager

2 comments

Discussion is closed.Login to edit/delete existing comments.

Stay informed

Get notified when new posts are published.
Follow this blog
youtube