Skip to content

Unit tests aren't discovered in sub-folders #11969

@ItsDrike

Description

@ItsDrike

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.80290
  • OS and version: Arch Linux (kernel: linux 5.6.14.arch1-1)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.3 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv
  • Relevant/affected Python packages and their versions: unittest
  • Relevant/affected Python-related VS Code extensions and their versions: None
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): True
  • Value of the python.languageServer setting: Microsoft

Actual behaviour

In main tests/ directory are some tests and some other files needed. Those work fine until a subdirectory is created, which contains 2 tests named test_decorators.py and test_pagination.py, this subdirectory also contains the __init__.py so that the tests can be recognized. After this subdirectory is created, the tests from main directory (tests/) disappear and the ones from subdirectory are not displayed either, a popup saying that no tests were discovered and asking me to configure the test framework (It is configured properly)

Once the __init__.py file is added and I rediscover the tests, this box pops up.
image

Expected behaviour

When I add the subdirectory to main tests/ directory and search for the tests, both the tests from my main directory and the subdirectory should be found.

Steps to reproduce:

  1. Create directory for tests in root of your project tests/
  2. Configure the framework to use unittests and recognise files labeled: test_*.py
  3. Add some tests in it and let the framework discover them [To this point everything is as expected]
  4. Add a subdirectory in your tests/ directory and place some other tests in it
  5. Run test discovery again
  6. No tests were found

Peek 2020-05-24 16-07

Logs

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: getActivatedEnvironmentVariables, Class name = E, completed in 1ms, has a truthy return value, Arg 1: <Uri:/home/itsdrike/Programming/Python/Projects/Discord-Bot>, Arg 2: undefined, Arg 3: undefined

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -c "import unittestloader = unittest.TestLoader()suites = loader.discover("./tests", pattern="test_*.py")print("start") #Don't remove this linefor suite in suites._tests:    for cls in suite._tests:        try:            for m in cls._tests:                print(m.id())        except:            pass"

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: cwd: ~/Programming/Python/Projects/Discord-Bot

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from posterinvestigatingWe are looking into the cause of the issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions