2

I've recently installed VSCode and it's python extension. Everything is going great but the test explorer won't populate with tests. I've run test discovery and I can even run the tests but the explorer won't populate with any information.

enter image description here

In the above screenshot we can see

  1. the empty test explorer
  2. my python vscode settings
  3. the output of test discovery

What's going on here?

NOTE: the problem is one that's expected, one test get's skipped unless a certain flag is passed to pytest and that's causing this "problem

Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94

3 Answers3

9
  1. You have to configure your test environment (and the launcher). Press cntrl + shift + p and search for: Python: Configure Tests (Assuming you already have Python extension installed).
  2. Then, the console will show you several options (unittest, pytest, nose...), select one of them.
  3. After that, the console will ask you the directory containing the test, choose yours.

After this configuration, you should be able to see all your test into the Test Explorer.

Gerard Auguets
  • 109
  • 1
  • 3
1

Turns out something was misconfigured. VS Code eventually automatically prompted me to change my unit test settings in settings.json from python.unitTest.<stuff> to python.testing.<stuff> which fixed the test explorer.

Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94
1

I think this is still on development, officially, only Pytest and Unittest are supported, but the VSCode suggested a variable to support Poetry.

Here are the configurations that have worked to me:

{
  "python.testing.cwd": ".",
  "python.poetryPath": ".venv/bin/poetry",
  "python.testing.pytestEnabled": true,
  "python.testing.pytestPath": ".venv/bin/pytest",
  "python.analysis.typeCheckingMode": "basic",
  "python.testing.pytestArgs": [
    "${workspaceFolder}",
    "--rootdir=${workspaceFolder}"
  ],
  "python.testing.unittestEnabled": false,
}

If you additionally needs to use environment variables, set them up in a .env file (it would be better a .env.test, but I couldn't figure it out).