DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Instant APIs With Copilot and API Logic Server
  • Debugging Tips and Tricks for Python Structural Pattern Matching
  • Comparison of Various AI Code Generation Tools
  • Static Analysis with ESLint and LWC

Trending

  • Event-Driven AI Systems With Kafka and Autonomous Agents
  • The Request Timed Out, But the Payment Succeeded: Building Retry-Safe Mobile APIs
  • Common REST Design Pattern
  • Android Application Security: Android Application Architecture

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. How to Set Up Visual Studio Code for Python Testing and Development

How to Set Up Visual Studio Code for Python Testing and Development

VS Code is an open-source, light-weight IDE that is gaining popularity due to its flexibility and cross-platform support.

By 
Madhu Suresh Nandyala
·
Aug. 30, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
107.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Image title

Learn more about using VS Code for Python testing and development

VS Code is an open-source, light-weight IDE that is gaining popularity due to its flexibility, ability to configure different programming languages, and cross-platform support. The following tutorial will walk you through how to set up a development and test environment in Python.

  • Download VS Code here
  • Install Python and configure your environment if you haven’t done so already
Interested in VS Code for Java development? Check out Visual Studio Code for Java: The Ultimate Guide 2019.

We will cover the following topics:

  • Configuring VS Code for Python
  • Configuring the debugger
  • Configuring Liniting: PEP8
  • Configuring Pytest

Let's get started!

Configuring VS Code for Python

Open the VS Code:

Opening VS code for Python

Install the Python extension from your extensions:

Python extensions for VS Code

Create a project workspace/folder. File -> Open Folder

Opening a folder in VS Code

Select a Python interpreter.

Open Command Palette (ctrl +shift +P) and start typing ‘python: select interpreter.’It will display a list of available Python environments.

VS Code command palette

Create a new file and IntelliSense. IntelliSense will work for standard modules and packages installed.

VS Code IntelliSense

When running a program, go to the Editor and right-click select ‘run python file in terminal.’ The output will be displayed in the terminal, as below:

VS Code Editor

Configuring Debugger

To initialize debug configurations, first select the Debug View in the sidebar:

If you don't yet have any configurations defined, you'll see No Configurations in the drop-down list, and a dot on the settings icon:

No Configurations in VS Code

From the settings, you can configure the debugger, selecting default debugger here.

Configuring the debugger in VS Code

Configuring Linter: PEP8

Open Command Palette (ctrl +shift +P) and start typing ‘python: select linter.’ It will display a list of available Python linters. You can add any of the settings to your user settings.json file (opened with the File > Preferences > Settings:

Configuring Linter PEP8 in VS Code

Configuring Tests: Pytest

The VS Code Python extension supports unit tests as well as pytest. Here's how to enable the framework:

Open Command Palette (ctrl +shift +P) and start typing ‘python: configure tests.’ It will display a list of available python linters. You can add any of the settings to your user settings.json file (opened with the File > Preferences > Settings

Configuring tests with Pytest in VS Code

After configuring the tests, it will display the following, opening the test will ask for the test location, in the following example selected the root folder.

If discovery succeeds, the status bar shows Run Tests instead:

Run tests in VS Code

If discovery fails (for example, the test framework isn't installed), you see a notification on the status bar. Selecting the notification provides more information:

Test discovery failed in VS Code

Running tests can be done at test level or suite level, as shown in the below screen:

Running tests on VS Code

Test results can found here:

VS Code test results

Further Reading

Visual Studio Code for Java: The Ultimate Guide 2019

Visual Studio Code Python (language) unit test

Opinions expressed by DZone contributors are their own.

Related

  • Instant APIs With Copilot and API Logic Server
  • Debugging Tips and Tricks for Python Structural Pattern Matching
  • Comparison of Various AI Code Generation Tools
  • Static Analysis with ESLint and LWC

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook