After initial test discovery, cannot discover new tests (unittest)
See original GitHub issueEnvironment data
- VS Code version: 1.25.1
- Extension version (available under the Extensions sidebar): 2018.7.1
- OS and version: MacOS 10.13.6
- Python version (& distribution if applicable, e.g. Anaconda): 3.70
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
- Relevant/affected Python packages and their versions: N/A
Actual behavior
Upon discovering unit tests, only one test file is found.
Running Discover Unit Tests does nothing (no errors, just nothing)
Run All Unit Tests continues to run original tests found in first discovery.
Run Unit Test File only shows original test.py
file discovered during initial discovery.
Expected behavior
Running Discover Unit Tests should find tests. Saving a test tile, should result in newly discovered tests Run Unit Test File… should show a list of several test files
Steps to reproduce:
The workspace has a directory structure like the below. It’s basically a bunch of coding exercises that I’ve written test cases for. Each directory has a python file (index.py) with the program and a test file (test.py) for the tests. . ├── anagrams │ ├── index.py │ └── test.py ├── capitalize │ ├── index.py │ └── test.py ├── chunk │ ├── index.py │ └── test.py …
Unittest test arguments are:
"python.unitTest.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test*.py"
],
- Setup testing framework (unittest):
"python.unitTest.unittestEnabled": true
- run Discover Unit Tests
- run Run All Unit Tests Output is:
test_anagrams_1 (test.AnagramsTests) ... ok
test_anagrams_2 (test.AnagramsTests) ... ok
test_anagrams_3 (test.AnagramsTests) ... ok
test_anagrams_4 (test.AnagramsTests) ... ok
test_function_exists (test.AnagramsTests) ... ok
----------------------------------------------------------------------
Ran 5 tests in 0.003s
OK
- run Discover Unit Tests while in several different directories (e.g. capitalize, chunk)
- run Run All Unit Tests* Output is the same as step 3 above.
- run Run Unit Test File… Only shows anagrams/test.py
- Open integrated terminal.
- change to capitalize directory
- run
python3 -m unittest
: 3 tests (correct forcaptialize/test.py
) run as expected - change to chunk directory
-
- run
python3 -m unittest
: 5 tests (correct forchunk/test.py
) run as expected
- run
- rename
chunk/test.py
tochunk/test_chunk.py
- run Discover Unit Tests : same behavior as above
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@kimfucious yes,
.pyc
files will be generated as part of test discovery because all of the test runners import your Python code to introspect it to find your tests.@kimfucious Imports actually shouldn’t be in your
__init__.py
(you almost always want those files to be empty). Could you provide a zip file of your code or something equivalent for us to test on our side? And does executing all your tests manually from the terminal work?