Skip to content

Failure details in unittest discovery are not always logged. #5889

Closed

Description

I'm pretty sure that the fix for #5313 is incomplete. It does the right thing for pytest, but not for unittest. I'm opening a new issue (rather than re-opening #5313) since the old issue has already been closed.

The main problem is that in src/client/testing/unittest/services/discoveryService.ts, failures are ignored in the script that gets run (see getDiscoveryScript()). They should be logged and dealt with.

One possible solution could be to update the adapter script to handle unittest (in addition to the current pytest support).

Activity

  1. karrtikr commented on Jul 29, 2021

    @karrtikr

    If we have an invalid test to load, say test_2.py.

    """This unit test module can not be discovered.
    """
    import unittest
    x = y +2 # Invalid line as `y` is not defined
    
    
    class Test_ImportOuterModule(unittest.TestCase):
        def test_2_1(self):
            self.assertEqual(1, 2)
            return
    
        def test_2_2(self):
            self.assertEqual(1, 1)
            return
    
    
    if __name__ == "__main__":
        unittest.main()

    The testing script

    "C:/Users/karraj/AppData/Local/Programs/Python/Python36/python.exe" -c "
    import unittest
    import inspect
    
    def get_sourceline(obj):
        s, n = inspect.getsourcelines(obj)
        for i, v in enumerate(s):
            if v.strip().startswith('def'):
                return str(n+i)
        return '*'
    
    def generate_test_cases(suite):
        for test in suite:
            if isinstance(test, unittest.TestCase):
                yield test
            else:
                yield from generate_test_cases(test)
    
    loader = unittest.TestLoader()
    suite = loader.discover("./package/tests", pattern="*test*.py")
    
    print("start") #Don't remove this line
    for s in generate_test_cases(suite):
        tm = getattr(s, s._testMethodName)
        print(s.id().replace('.',':') + ":" + get_sourceline(tm))
    "

    returns

    start
    unittest:loader:_FailedTest:test_1:33
    unittest:loader:_FailedTest:test_2:33
    

    The last 2 entries indicate that the test nodes test_1 and test_2 were not loaded, this should probably be surfaced.

  2. karthiknadig commented on Aug 3, 2021

    @karthiknadig
    Member

    With the latest test-UI this is addressed:
    image

  3. locked as resolved and limited conversation to collaborators on Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bugverifiedVerification succeeded

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions