0

I have 2 classes, A and B.

class A (unittest.TestCase):
   #methods here

class B (A):
   #methods here

when i try and call self.assertEqual(1,1) in a method of class B, I get the error mentioned here: Why do I get an AttributeError with Python3.4's `unittest` library? Yet if I call it in A, everything is fine. Does unittest not follow regular inheritance? Is there only a very specific way you can use it?

  • Possible duplicate of [Python unit test with base and sub class](https://stackoverflow.com/questions/1323455/python-unit-test-with-base-and-sub-class) – vishes_shell Jul 25 '17 at 22:34

1 Answers1

0

I have tried your example as such:

import unittest

class A(unittest.TestCase):
    def test_a(self):
        self.assertEqual(1, 1)

class B(A):
    def test_b(self):
        self.assertEqual(2, 3)


if __name__ == '__main__':
    unittest.main()

and it worked, this is test result:

test_a (__main__.A) ... ok
test_a (__main__.B) ... ok
test_b (__main__.B) ... FAIL
bbb
  • 1
  • 2