This question already has an answer here:
- What does 'super' do in Python? 5 answers
I am overriding setUpClass() of TestCase as per django documentation.
class Health_showhome(TestCase):
@classmethod ##setUpClass must be called with instance of Health_showhome()
def setUpClass(cls):
super(Health_showhome, cls).setUpClass()
db = MySQLdb.connect(host="localhost",user="root",passwd="mcvishu007")
cls.cursor = db.cursor()
query = 'CREATE DATABASE IF NOT EXISTS testxxx;'
cls.cursor.execute(query)
query = 'USE testxxx;'
cls.cursor.execute(query)
@classmethod
def tearDownClass(cls):
query = 'DROP DATABASE testxxx;'
print "teardown"
cls.cursor.execute(query)
cls.cursor.close()
The method creates database without super() function. So i am confused with the use of super() function.super(Health_showhome, cls).setUpClass()
is actually as TestCase.setUpClass()
, isn't it?
What is the use of super() function ? How they works?
Aucun commentaire:
Enregistrer un commentaire