Can't figure out testing in python. More specifically, backend testing on django. The challenge is this. There is a class A with doAA and doBB methods. Accordingly, there is a test class TestA (unittest.TestCase), containing tests testDoAA and testDoBB.

Everything is fine and everything suits, but until then, until the class B appears, the set of methods is identical to class A.

That is, B and A perform some tasks slightly differently. To write one more class, such as TestB, with copying there everything from TestA is seen as barbaric and in the wrong way.

Tell me, how can I describe the test once and run it twice for two similar classes? and forgive me for terminological and other errors, for me, Python is a new and painfully unusual language.

ps: I wanted to call the question like this: "Run python unittest for the interface, not for the class", but this is not exactly the case.

    1 answer 1

    The TestCase class has a setUp method that allows you to set general data for all methods; this solves some problems.

    To write one more class, such as TestB, with copying there everything from TestA is seen as barbaric and in the wrong way.

    You work with OOP. Here, just like in your classes A and B, it is necessary to bring the general functionality to the class above (generalization). You do not have code in classes, I think so? So when testing, it should not be repeated due to the same techniques.

    • Yes! Thank! As a result, I inherited two TestA and TestB classes from the main TestCase, each of which in the setUp is already asking which of the heirs of the base class A and B to work with. - chuchuchu