mercredi 23 août 2017

What is the need for super() in overriding TestCase.setUpClass() [duplicate]

This question already has an answer here:

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