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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

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

  • Mastering Advanced Aggregations in Spark SQL
  • How Can Developers Drive Innovation by Combining IoT and AI?
  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • Memory Leak Due to Time-Taking finalize() Method
  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 user avatar
Madhu Suresh Nandyala
DZone Core CORE ·
Aug. 30, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
106.1K Views

Join the DZone community and get the full member experience.

Join For Free

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
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!