Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only.Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Python Unit Testing With VS Code
VS Code can automatically recognize existing Python tests and run them. Learn how to configure it to run test suites, individual tests as well as view test output.
Link to PyEval repo:https://github.com/JFincher42/PyEval.git
00:00Just like the full-fledged version of Visual Studio, VS Code allows for easy unittesting,which allows us to test specific parts of our code one at a time. To demonstratethis I’m going to use PyEval,a Python library for parsing equations written in infix notation.
00:20This was written by Jon Fincher, theoriginal author of the article that this video series is based on.He used to work at Microsoft,so you know that this material is good stuff. To start,we’re going to open the Command Palette by hitting Command + Shift + P,or Control + Shift + P on other systems.
00:39Now we’ll typeshell and select the command that saysInstall ‘code’ command in PATH.What this will do is add Visual Studio Code to your system path,which dictates what folders your terminal searches for when it tries to run aprogram that you specify.
00:58Now I’ll clone Jon’s repository to my local machine,I’ll open a new system terminal here—there we go.And I’ll change directory to the desktop by typingcd Desktop/.
01:12Now we’ll typegit clone and paste in the clone URL.This link will be available in the description down below the video.We’ll press Enter and let Git clone the remote repository to my machine.
01:28Now that it’s done,we can move into the cloned repository by typingcd PyEval/. To open this folderwithin Visual Studio Code,we can typecode dot (.).
01:41Here,code is the name of the binary that launches VS Code,and this is works because we added VS Code to the system path.The. represents the current directory,so we’re basically telling VS Code to open the current directory when we pressEnter. And there we go! On the left,you’ll see all of the files in this project.
02:03Let’s click onexpr_test.py.This file contains all of the unit tests that can be run. Right now, VSCode is complaining at me because thisproject came with asettings.json file specifying where the Python pathis, as well as some other files for Python.
02:23Your mileage may vary with this if you’re using a virtual environment,but right now I’m not using one.So here’s how we can fix this. First,I’ll click on this button here to bring up this familiar menu,which lets us change our Python interpreter.
02:40I’ll select the latest version installed on my system.But now it’s still complaining to me that it can’t findunittest. To make surethat our change has actually been applied,we can head over to thesettings.json file under the.vscode/ directory.
02:58We’ll make that the Python path here is set correctly.This right here should point to the Python executable on your system.The settings file downloaded from the repository sets this to"/usr/local/bin/",which is where Python is installed on Linux. I’m using macOS right now,so selecting the Python interpreter a moment agoupdated this file to reflect the correct location of my Python interpreter.
03:25Once you’re positive that this is correct for your system,we’ll go ahead and restart VS Code.
03:36Now, if we go back into ourexpr_test file,all of the errors should be gone. Again,this may not be an issue for you at all,depending on your configuration and how you’re running your program.
03:50I just showed you an easy way to fix any settings that might come with a Gitrepository that don’t quite line up with the system settings you need.Now we can finally run our unit tests. In the status bar at the bottom here,you’ll notice a little lightning bolt that saysRun Tests. Click on that,and then at the very top, chooseRun All Unit Tests.
04:14After a few seconds, you should see a green check mark.This is telling us that all of our tests passed. To actually view test results,click on the check mark and chooseView Unit Test Output at the top.
04:28This will show us a log of each test that ran.If you don’t see any output here,make sure that theOUTPUT panel is set toPython Test Log.
04:39You can also run individual tests by clicking on the check mark at the bottomand then choosingRun Unit Test Method….And now we can pick a single test to run.
04:51I’ll choose this one right here. And now we’ve run just one test,as you can see in the output panel below. This way,if you just want to run a specific test,you don’t have to wait for all of the other tests to finish first.
05:05Alternatively,you can also find the class or test method in your code and then click onRun Testabove the definition. In the next video,we’ll learn how to debug our Python programs.
Brendan Leber onApril 5, 2019
FYI, if you are running the “Insider’s Edition” the shell command to run is “code-insiders .”

Austin CepaliaRP Team onApril 5, 2019
Great tip! I’ll add it to the video descriptions I’m writing now
AugustoVal onApril 6, 2019
Hello Austin,
Where could I find the link for the repo?
Jacob Andersen onApril 7, 2019
I’m using visual studio code for windows and can’t seem to find the shell command shown 43 seconds into the video. I open the command palette just fine, but there is no sign of the ‘install code command in PATH ’ statement.

Austin CepaliaRP Team onApril 7, 2019
It appears that the VS Code installer for Windows automatically adds the program executable to the PATH, so that step can be ignored. You should still be able to type “code .” in your command prompt or bash shell, just as I did in the video.
haleybear onApril 24, 2019
link to repo:github.com/JFincher42/PyEval.git
Anonymous onJuly 24, 2019
I have no shell command ” Install ‘code’ Command in path”
Anonymous onJuly 24, 2019
Code is not automatically installed in path on my windows machine.
nskgithub onNov. 26, 2019
I have the same issue as below:
I’musingvisualstudiocodeforwindowsandcan’tseemtofindtheshellcommandshown43secondsintothevideo.Iopenthecommandpalettejustfine,butthereisnosignofthe‘installcodecommandinPATH‘statement.I tried running git command and am getting git is invalid identifier
danP onNov. 1, 2021
Currently using VS Code 1.61.2, and the interface seems to have changed rather significantly.
The full testing interface can be reached from the “beaker” in the left navigation (code.visualstudio.com/docs/python/testing#test-discovery for screenshots), and I have no “run tests” option in the bottom status bar.
Also, in the command palette, the commands for unittest begin with Test: (eg, Test: Run All Tests).
CG-Tespy onNov. 14, 2022
Am running VS Code 1.73.1 at the moment, and I tried the Run All Tests command. I got a popup telling me that there’s no test framework configured. For those who don’t know what to do from this point on, here’s what I did:
- Click “Configure Test Framework” on the popup that said “No test framework configured”
- The Command Palette should then open. Choose the unittest Standard Python Test Framework option it gives you
- It’ll then ask you what directory contains the tests. Choose the root
- It’ll then ask you the pattern to identify test files. Choose (asterisk)(underscore)test.py
- Wait a few seconds
- Now you can run all tests
I hope this helps
Luke onMarch 25, 2023
CG-Tespy this helped a lot, thank you. I was very confused by the video, until I found your comment.
Ranga onApril 5, 2023
@CG-Tepsy, that was very helpful indeed. Thank you.
Dakkon onApril 24, 2023
Likewise - CG-Tespy, thanks for the tip! I was frustrated with the video until I read your comment, which was seriously helpful.
Morris Johnson onDec. 20, 2023
Interesting to see how testing was made possible in the past. Unfortunately, there have been too many change in vs code since this video was made to make much use of it.
waqe onMarch 29, 2025
bump
Interesting to see how testing was made possible in the past. Unfortunately, there have been too many change in vs code since this video was made to make much use of it.
Become a Member to join the conversation.
Course Contents

