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

Install

Use easy_install (or pip):

$ easy_install testing.mysqld

And testing.mysqld requires MySQL server in your PATH.

Usage

Create MySQL instance using testing.mysqld.Mysqld:

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

# connect to MySQL
from sqlalchemy import create_engine
engine = create_engine(mysqld.url())

# if you use mysqldb or other drivers:
#   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})

Requirements

  • Python 2.7, 3.3

  • pymysql

License

Apache License 2.0

History

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.

Source Distribution

testing.mysqld-1.1.2.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file testing.mysqld-1.1.2.tar.gz.

File metadata

File hashes

Hashes for testing.mysqld-1.1.2.tar.gz
Algorithm Hash digest
SHA256 e2530f6011d3ac13156de3ac39b2786f120f62dabf264eaad8904ead60fbedc0
MD5 1b47ac4164af4ed92b2ea9c35c273e0f
BLAKE2b-256 99a9c0a251b91d2dca3c78d126d0e58f6b6143b39826de9414992d7ebceb119b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page