Python tests in more than one file in Visual Studio Code

603 Views Asked by At

I'm using unittest library to run some tests for a Python/Django application, using Visual Studio Code. They work just fine. The only issue is that I have the tests located in more than one file, and I can't get VS Code to run them all at one single click, I have to run each file separately. My structure goes something like this:

/applications (folder)
   /folder1
      python_file_1.py
      python_file_2.py
      ...
      test_first.py
   /folder2
      python_file_3.py
      python_file_4.py
      ...
      test_second.py
      test_third.py

This produces this tree in the test explorer:

enter image description here

The files test_*.py contain my three sets of tests but, like I said, I can only run them one at a time. If I click on the play button at /applications level, VS Code only runs the tests in test_integration_comun.py file. Is there a way to run all 3 with just one click?

This is the settings.json file that VS Code added when I configured unittest:

{
    "python.testing.unittestArgs": [
        "-v",
        "-s",
        "./applications",
        "-p",
        "test_*.py"
    ],
    "python.testing.pytestEnabled": false,
    "python.testing.unittestEnabled": true
}

Thanks in advance for the help :)

1

There are 1 best solutions below

2
On

To run all discovered tests, select the play button at the top of Test Explorer:

enter image description here

To run a specific group of tests, or a single test, select the file, class, or test, then select the play button to the right of that item:

enter image description here