Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handle unittest module #4319

Closed
MikhailArkhipov opened this issue Jun 4, 2018 · 1 comment
Closed

Better handle unittest module #4319

MikhailArkhipov opened this issue Jun 4, 2018 · 1 comment
Assignees
Labels

Comments

@MikhailArkhipov
Copy link

# https://docs.python.org/3/library/unittest.html#module-unittest
import unittest

class Simple(unittest.TestCase):
    def test_success(self):
        self.assertEqual()  # Funky: docs don't' show method arguments.

    def test_exception(self):
        with self.assertRaises(Exception) as em:
            raise Exception
        exc = em.exception # Fails: doesn't infer `exception`.
        with self.assertRaisesRegex(ValueError, 'literal') as em2:
            int('XYZ')
        em2.exception

    def test_logging(self):
        with self.assertLogs('foo', level='INFO') as cm:
            pass
        cm.output # Fails: doesn't infer `output`.

    def test_subtests(self):
        for i in range(0, 6):
            with self.subTest(i=i):
                self.assertEqual(i % 2, 0)



def load_tests(loader, tests, pattern):
    suite = unittest.TestSuite()
    for test_class in test_cases:
        test = loader.loadTestsfromTestCase(test_class)
        suite.addTests(tests)
    return suite


if __name__ == '__main__':
    unittest.main()
@MikhailArkhipov
Copy link
Author

Works well with typeshed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant