testing python applications that use mysql

mysql, python, unit-testing

Solution

There isn't a good way to do that. You want to run your queries against a real MySQL server, otherwise you don't know if they will work or not.

However, that doesn't mean you have to run them against a production server. We have scripts that create a Unit Test database, and then tear it down once the unit tests have run. That way we don't have to maintain a static test database, but we still get to test against the real server.

Problem

I want to write some unittests for an application that uses MySQL. However, I do not want to connect to a real mysql database, but rather to a temporary one that doesn't require any SQL server at all. Any library (I could not find anything on google)? Any design pattern? Note that DIP doesn't work since I will still have to test the injected class.

Original source