[Tutor] Unittest question

Albert-Jan Roskam sjeik_appie at hotmail.com
Wed Aug 3 03:47:34 EDT 2022


   On Aug 2, 2022 09:22, Peter Otten <__peter__ at web.de> wrote:

     No patience to read the stackoverflow suggestions in your follow-up
     posts, but here's a simple approach that should be good enough to solve
     the actual problem: parameterize test *classes* with the module (or
     module name).

     import unittest

     class CommonTests(unittest.TestCase):
         def test_impl(self):
             self.module.whatever()

     class CFFITests(CommonTests):
          import foo as module

     class CtypesTests(CommonTests):
          import bar as module

     del CommonTests  # without that you get three tests

     if __name__ == "__main__":
          unittest.main()  # rely on the default test discovery mechanism

   ====
   Hi Peter,
   Thank you! Very similar to the technique thet use in the Python source
   code (see the last link that I posted). Good idea to simply delete the
   Common class!  Much better than skipping those tests.
   Best wishes,
   Albert-Jan


More information about the Tutor mailing list