top of page
  • Writer's pictureGio

HOWTO Configure Pytest on Visual Studio Code

Updated: Dec 10, 2022


If you want to design and debug unit tests using pytest on Visual Studio Code, a.k.a. VScode, then you are in the right place.


Requirements
  • Open any project within VScode repository where you intend to add unit tests. You can clone this repo which is the one used for this tutorial.

  • pytest should be already installed in your python environment (conda or virtualenv)


Step-by-step procedure

Click on the Cruet icon on the left panel, then on Configure Python Tests and select pytest.

Specify the name of the folder where the unit tests are stored; in 99.99 % of the case, the folder name is called test as shown below.


That's it 🥳🥳🥳!!! you should be able to see all the unit tests stored in the test folder on the left hand side of VScode (for this repo, there is only one unit test), and you will be able to perform three new operations:

  • 1 run one single unit test that you are interested in;

  • 2 run the unit test in debug mode (make sure that you place a 🔴 Breakpoint somewhere within the test function you want to debug);

  • 3 redirect you to a specific unit test. This is handy if you have many tests nested in many subfolders.



374 views
bottom of page