Reputation: 11
I have a parent class for all my tests, which inherited from the unittest.TestCase. It contains a lots of global variables, and a bunch of custom functions for creation and deletion users and other entities.
class AutoTest(unittest.TestCase):
def vars(self):
self.api = "http://"
self.auth = HTTPBasicauth("arr", "yarrr")
def new_user(self):
requests.post(url, json, auth)
return response
""""and so on"""
The problem is that I need to prepare test data for test suites and it should be prepared once for all tests in suite (i.e test class).
As far as I understand, for such cases a setUpClass
is used, but it's used only as class method, so all defined in parent class ustom functions, which is absolutely crucial for test data preparing become uncallable from it because all of them are instance methods and have "self" positional argument.
class TestSomeStuff(AutoTests):
def setUpClass(cls):
*and here is the problem, because none of the AutoTest class functions are available*
Will appreciate any help/advices.
Upvotes: 1
Views: 617
Reputation: 106455
Call the parent class's setUpClass
method with super()
. Also you should always decorate setUpClass
with @classmethod
.
class TestSomeStuff(AutoTests):
@classmethod
def setUpClass(cls):
super(TestSomeStuff, cls).setUpClass()
Upvotes: 1