简体   繁体   中英

Python unittest does not find attribute

I'm writing an INTEGRATION test using Visual Studio 2019, Python and the unittest library.

I have this code:

import unittest
import mysql.connector as mysql

class Test_Database_Integration_test(unittest.TestCase):

    def setup(self):
        self.db = mysql.connect(
                host = "localhost",
                user = "root",
                passwd = "password",
                database = "database")
        self.cursor = self.db.cursor() 


    def truncate_database(self):
   
        query = "TRUNCATE `database`.`map_start_conditions`"

        self.cursor.execute(query)
        self.db.commit()


    def test_Truncate_Database(self):

        self.truncate_database()

        query = "SELECT * FROM `database`.`map_start_conditions`"

        self.cursor.execute(query)
        records = self.cursor.fetchall()
        assert len(records) == 0

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

When I run this I get an error that Test_Database_Integration_test does not have a cursor attribute.

Why is this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM