VS Code has a nice interface for running your tests. By default, it’s not visible, although the Python extension might sometimes ask you if you want to configure it. If it doesn’t, here is how to enable it:
VS Code will blink a couple of times, and a magic potion icon should appear in the sidebar.
Here are the new superpowers that VS Code just enabled:
The magic potion icon is a “Test” tab. It contains a list of all the tests that VS Code found (across all the test files). You can also see at a glance which tests are passing and which are failing. At the top of the sidebar, you will find a few useful buttons:
Above each test function, you will see small annotations: “Run Test” and “Debug Test” together with “✓” sign for passing tests and “⚠” sign for failing ones. You can put breakpoints in your tests and select the “Debug Test” option to start a debugger and see what’s going on in your test.
If you create a
pytest.ini file and modify some pytest settings there, VS Code will respect those changes when running tests.