There are two ways you can run the unit tests in order to grade your code:
- Option #1: Running Unit Tests in VS Code with Testing
- Option #2: Running Unit Tests in Your Terminal
To run the tests directly in VS Code do the following:
- Press Code and copy the HTTPS URL that is provided.
- In your terminal, type the following replacing PASTE_URL_HERE with the URL you copied.
git clone PASTE_URL_HERE- This will clone the code down to your machine. You can navigate into the folder by typing:
cd FOLDER_NAMENOTE: You can get the folder name by typing the command ls.
- Open the
practice filein VS Code.
code practice.pyNOTE: The code command opens the file directly in VS Code. You can set this up using the documentation (Windows and Mac).
- Click the flask icon in the left tool bar.
- Next, click "Configure Python Tests".
- You'll have two options to select. Select pytest.
- Select the folder that contains the tests. In this case you should select tests. You can always change this in the
settings.jsonfile that will be created in a.vscodefolder for you.
- You can now run the tests by pressing the play icon. Press the play icon to see if the tests pass. Oh no!
two_plus_twoseems to fail.
- In
practice.py, find thetwo_plus_twofunction. You’ll notice it is not returning the correct value. Update the function so that it returns the value. - Run the tests again and you should see that they are all passing!
Unit tests can be run directly in the terminal. This can be done using the following steps.
- Repeat steps 1 to 4 from the previous section.
- Once the code file is open, navigate to the terminal and ensure you are in the correct folder.
- Run the following command in your terminal
pytest --v- This will output a response that looks like the image below.
- The image above shows that the function two_plus_two is failing because it is returning 5, but the test is expecting 4.
- In
practice.py, find the two_plus_two function. You’ll notice it is not returning the correct value. Update the function so that it returns the value. - Run the command in step 3 to run tests again and you should see that they are all passing!







