[Tutor] Unittest question

Albert-Jan Roskam sjeik_appie at hotmail.com
Sun Jul 31 12:19:42 EDT 2022


   Hi,
   I am trying to run the same unittests against two different
   implementations of a module. Both use C functions in a dll, but one uses
   ctypes and the other that I just wrote uses CFFI. How can do this nicely?
   I don't understand why the code below won't run both flavours of tests. It
   says "Ran 1 test", I expected two!
   Any ideas?
   Thanks!
   Albert-Jan

   import unittest

    

   class MyTest(unittest.TestCase):

    

       def __init__(self, *args, **kwargs):

           self.implementation = kwargs.pop("implementation", None)

           if self.implementation == "CFFI":

               import my_module_CFFI as xs

           else:

               import my_module as xs

           super().__init__(*args, **kwargs)                                 

    

       def test_impl(self):

           print(self.implementation)

           self.assertEqual(self.implementation, "")

    

   if __name__ == "__main__":

       suite  = unittest.TestSuite()

       suite.addTests(MyTest(implementation="CFFI"))

       suite.addTests(MyTest(implementation="ctypes"))   

       runner = unittest.TextTestRunner(verbosity=3)

       runner.run(suite)

    

   ###Output:

   AssertionError: None != ''

   -------------------- >> begin captured stdout << ---------------------

   None

    

   --------------------- >> end captured stdout << ----------------------

    

   ----------------------------------------------------------------------


More information about the Tutor mailing list