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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With