[Tutor] Unittest question
Peter Otten
__peter__ at web.de
Tue Aug 2 03:22:59 EDT 2022
On 31/07/2022 18:19, Albert-Jan Roskam wrote:
> 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?
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
More information about the Tutor
mailing list