Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking DB python

Tags:

python

mocking

Is there a simple mock example to test connection db in python? I find much examples by google, but I'm confused. I'd like to test a connection db and execute a query, to understand concepts, for example cursor.

THANKS

like image 714
user1410756 Avatar asked Mar 13 '26 05:03

user1410756


1 Answers

If you want to understand the concepts, I think mocking isn't the best solution for you.

I would advise actually setting up a simple Database, for instance, SQLite3, creating some tables, connecting to it via Python, and doing some tests.

To be able to mock something, you need to know what behavior you are expecting from the object you are mocking, if you want to learn how it works, then your best answer is to actually try it out.

Sqlite3 is builtin into most recent versions of Python, so you can test it by simply opening a python shell and typing in import sqlite3.

Check out this tutorial for some hints on what you can do:

http://zetcode.com/db/sqlitepythontutorial/

like image 195
pcalcao Avatar answered Mar 14 '26 17:03

pcalcao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!