Running Python Tests in VSCode

July 18, 2019

VSCode has a pretty sweet test runner integrated into the editor so you don't have to switch back into the terminal to run your unit tests.

If you already have tests in your repo, you can have VSCode try to detect where they're located. VSCode has support for unittest, pytest, and nosetests.

For example, if we use unittest and you need to pass in arguments, you can define them with python.testing.unittestArgs. Also, python.testing.autoTestDiscoverOnSaveEnabled is set to true by default so you can pass in the test file naming pattern like so:

  "python.testing.unittestArgs": [
  "python.testing.pytestEnabled": false,
  "python.testing.nosetestsEnabled": false,
  "python.testing.unittestEnabled": true

One really cool feature is the CodeLens adornment in your test file. You have the option of running a specific test just with one click.

This feature probably won't fit in completely with a BDD/TDD workflow, but I think it's just an added nicety that makes VSCode the best editor for Python currently.


I'd like to send you a weekly recap of all the articles I write as well as my take on the latest news on web development with Vue, React, Elixir/Phoenix, and others. Just fill out your email and name below!

Prev: Emmet Abbreviations in Jinja Files
Next: Thoughts on the Mega-Tutorial