question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After initial test discovery, cannot discover new tests (unittest)

See original GitHub issue

Environment 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"
  ],
  1. Setup testing framework (unittest): "python.unitTest.unittestEnabled": true
  2. run Discover Unit Tests
  3. 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
  1. run Discover Unit Tests while in several different directories (e.g. capitalize, chunk)
  2. run Run All Unit Tests* Output is the same as step 3 above.
  3. run Run Unit Test File… Only shows anagrams/test.py
  4. Open integrated terminal.
  5. change to capitalize directory
  6. run python3 -m unittest : 3 tests (correct for captialize/test.py) run as expected
  7. change to chunk directory
    1. run python3 -m unittest : 5 tests (correct for chunk/test.py) run as expected
  8. rename chunk/test.py to chunk/test_chunk.py
  9. run Discover Unit Tests : same behavior as above

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Aug 15, 2018

@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.

1reaction
brettcannoncommented, Aug 14, 2018

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

After initial test discovery, cannot discover new tests (unittest)
Steps to reproduce: · run Discover Unit Tests while in several different directories (e.g. capitalize, chunk) · run Run All Unit Tests* Output...
Read more >
unit testing - `python -m unittest discover` does not discover tests
The behaviour is intentional, but the documentation could make this clearer. If you look at the first paragraph in the test discovery section,...
Read more >
Why is Python Unittest file not discovered? - TechBrij
It is assumed you have already setup proper unit test configurations. The goal is to get exact reason why test method is not...
Read more >
Test Explorer not discoverying test methods
In code explorer select the test that hasn't run and run it (Right click - Run Selected Test). Confirm it passses.Immediately after attempt...
Read more >
Quick Fix: Python Unittest not Discovering Tests - YouTube
Hopefully this video will help you solve a slightly annoying problem with python unittest where unittest will not run the tests because it ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found