Running Python Tests in VSCode

Thu Jul 18 2019

Photo by Loudge on Unsplash

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.

If you found the post helpful and would like this same content delivered to you,

Subscribe to my newsletter