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.

New unittest discovery code doesn't discover all tests

See original GitHub issue

Repro steps:

  • Create a folder with a Python file and a tests folder
  • Inside the tests folder add a test file test_something.py (name can be anything as long as it starts with test_) with the following content:
import unittest


class Testing(unittest.TestCase):
    def test_string(self):
        a = "some"
        b = "some"
        self.assertEqual(a, b)

    def test_boolean(self):
        a = True
        b = True
        print("this is a test")
        self.assertEqual(a, b)


class OtherTesting(unittest.TestCase):
    def test_equal_string(self):
        a = "some"
        b = "some"
        self.assertEqual(a, b)

    def test_equal_boolean(self):
        a = True
        b = True
        self.assertEqual(a, b)


class IntegerArithmeticTestCase(unittest.TestCase):
    def testAdd(self):  # test method names begin with 'test'
        self.assertEqual((1 + 2), 3)
        self.assertEqual(0 + 1, 1)

    def testMultiply(self):
        self.assertEqual((0 * 10), 0)
        self.assertEqual((5 * 8), 40)
  • In your workspace settings, make sure that testing using unittest is enabled (look for the python.testing.unittestEnabled setting and tick the checkbox), and that the value of the python.testing.unittestArgs setting is as follows:
[
    "-v",
    "-s",
    "./tests",
    "-p",
    "test_*.py"
  ]
  • Use the current discovery code, notice that the unit tests under the Testing, OtherTesting and `IntegerArithmeticTestCase are found
  • Swap to the new discovery code, notice that not all of the tests are found

⚠️ It might have something to do with some of the test names being camelCase (testMultiply) while others are snake case (test_boolean). Both conventions should be supported anyway. Could also be that the current discovery algorithm stops at the first testing class.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
kimadelinecommented, Jun 13, 2022

That is for you to figure out and fix 🙂

0reactions
ksy7588commented, Jun 24, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Unittest: No tests discovered in Visual Studio Code
To check for a potential error, click the Show Test Output , then run the tests using Run All Tests (both buttons are...
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 >
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 >
TestExplorer test discovery for google tests doesn't work since ...
You must clean the Unittest DLL project and rebuild the Unittest exe afterwards... only this updates the complete test list.. Click to vote...
Read more >
Set up unit testing for Python code - Visual Studio
By default, Visual Studio identifies unittest and pytest tests as methods whose names start with test . To see test discovery, do the...
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