1

I can't seem to get vscode to detect tests for a simple project:

Folder structure:

~/Documents/My_proj$ tree
.
├── tests
│   ├── __init__.py
│   └── test_main.py
└── xyz
    ├── __init__.py
    ├── main.py
    ├── subpkg1
    │   ├── __init__.py
    │   └── modx.py
    └── subpkg2
        ├── __init__.py
        └── mody.py

main.py:

from xyz.subpkg1 import modx
from xyz.subpkg2 import mody

def a():
    return modx.x + mody.y

test_main.py:

from unittest import TestCase
from xyz import main

class TestA(TestCase):
    def test_a(self):
        self.assertEqual(main.a(), 30)

if __name__ == "__main__":
    unittest.main()

unittest config:

"python.unitTest.unittestArgs": [
    "-v",
    "-s",
    "./tests",
    "-p",
    "test_*.py"
]

Tests can be successfully run from the terminal with python3 -m unittest discover; tests also run fine when I click the "Run all tests" green triangle icon.

Yet when I click "Discover Tests", vscode tells me "No tests discovered, please check the configuration settings for the tests."

When I delete from xyz import main from test_main.py, vscode finally detects the test correctly, but this breaks the test.

I've gone through 10 similar StackOverflow questions (and a few github issues) without finding a solution.

What am I missing here?

Eric L
  • 592
  • 1
  • 6
  • 20
  • 1
    What version of the extension are you using? In version 2020.4.74986 there is an issue with `unittest` test discovery specifically that will be fixed in a bugfix release later this week. – Brett Cannon Apr 27 '20 at 20:42
  • 1
    Yes, I had `2020.4.74986`. Can confirm that update `2020.4.76186` fixed this issue, I'm now seeing a list of tests. Thank you! – Eric L Apr 29 '20 at 06:09
  • 1
    @Brett Cannon Well I am on version v2021.7.1053846006 and have the same issue, python -m unittest discover and Run All Tests works both fine, but the tests just won't show up in VScode... did the bug came back ? – bricx Jul 23 '21 at 17:10
  • @bricx possibly; please open an issue at https://github.com/microsoft/vscode-python – Brett Cannon Jul 24 '21 at 20:38

0 Answers0