def db(): print('----------setup----------------') db = StudentDB() db.connect('data.json') yield db print('----------teardown----------------') db.close()
def test_mark_data(db): db = StudentDB() # init class db.connect('data.json') scott_data = db.get_data('Mark') assert scott_data['id'] == 2 assert scott_data['name'] == 'Mark' assert scott_data['result'] == 'fail'
def test_scott_data(db): db = StudentDB() # init class db.connect('data.json') scott_data = db.get_data('Scott') assert scott_data['id'] == 1 assert scott_data['name'] == 'Scott' assert scott_data['result'] == 'pass'
def db(): print('-------------setup-------------') db = StudentDB() # just initialize StudentDB() db.connect('data.json') # call connect method to access the json datafile # return db # used without teardown yield db print('-------------teardown-------------') db.close()
def setup_module(module): print(" -> This is a setup method") global db db = StudentDB() db.connect("data.json")
def db(): print("=======SETUP=======") db = StudentDB() db.connect("data.json") return db