Skip to main content

automatically setups a mysqld instance in a temporary directory, and destroys it after testing

Project description

testing.mysqld automatically setups a mysqld instance in a temporary directory, and destroys it after testing


Use easy_install (or pip):

$ easy_install testing.mysqld

And testing.mysqld requires MySQL server in your PATH.


Create MySQL instance using testing.mysqld.Mysqld:

import testing.mysqld
mysqld = testing.mysqld.Mysqld()  # Lanuch new MySQL server

import _mysql
db = _mysql.connect(**mysqld.dsn())
# do any tests using MySQL...

del mysqld                     # Terminate MySQL server

testing.mysqld.Mysqld executes mysql_install_db and mysqld on instantiation. On deleting Mysqld object, it terminates MySQL instance and removes temporary directory.

If you want a database including tables and any fixtures for your apps, use copy_data_from keyword:

# uses a copy of specified data directory of MySQL.
mysqld = testing.mysqld.Mysqld(copy_data_from='/path/to/your/database')

You can specify parameters for MySQL with my_cnf keyword:

# boot MySQL server without socket listener (use unix-domain socket)
mysqld = testing.mysqld.Mysqld(my_cnf={'skip-networking': None})

For example, you can setup new MySQL server for each testcases on setUp() method:

import unittest
import testing.mysqld

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.mysqld = testing.mysqld.Mysqld(my_cnf={'skip-networking': None})


  • Python 2.7, 3.3
  • pymysql


Apache License 2.0


1.0.0 (2013-10-17)

  • First release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for testing.mysqld, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size testing.mysqld-1.0.0.tar.gz (8.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page