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

drone.io CI build status Latest PyPI version Number of PyPI downloads

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
from sqlalchemy import create_engine

# Lanuch new MySQL server
with testing.mysqld.Mysqld() as mysqld:
    # connect to MySQL
    engine = create_engine(mysqld.url())

    # if you use mysqldb or other drivers:
    #   import _mysql
    #   db = _mysql.connect(**mysqld.dsn())

    #
    # do any tests using MySQL...
    #

# MySQL server is terminated here

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})

    def tearDown(self):
        self.mysqld.stop()

Requirements

  • Python 2.6, 2.7, 3.2, 3.3, 3.4

  • pymysql

License

Apache License 2.0

History

1.2.5 (2014-06-11)

  • Fix ImportError if caught SIGINT on py3

1.2.4 (2014-02-13)

  • Fix testing.mysqld.Mysqld#start() fails if mysql_install_db does not create database named “test”

1.2.3 (2013-12-11)

  • Use pymysql driver as default in Mysqld#url()

1.2.2 (2013-12-06)

  • Change behavior: Mysqld#stop() cleans workdir

  • Fix caught AttributeError on object deletion

1.2.1 (2013-12-05)

  • Add mysqld.skipIfNotInstalled decorator (alias of skipIfNotFound)

  • Suport python 2.6 and 3.2

1.2.0 (2013-12-04)

  • Add @skipIfNotFound decorator

1.1.2 (2013-11-26)

  • Fix it does not cleanup temporary directory if Mysqld object has been deleted

1.1.1 (2013-11-25)

  • Add charset parameter to Mysqld#url()

1.1.0 (2013-11-22)

  • Rename package: test.mysqld -> testing.mysqld

  • Add Mysqld#url() method (for sqlalchemy)

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.2.5.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

testing.mysqld-1.2.5-py2.py3-none-any.whl (8.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for testing.mysqld-1.2.5.tar.gz
Algorithm Hash digest
SHA256 8d50029a2a79aa7febc94421e716a741a101083113543d0e8709af7ec0aa925a
MD5 caf2e44774e63f172e35cac9f8286b2a
BLAKE2b-256 157db6da4c367a68f9d7eb8db94ecaccd456eb17d40ad456db0a3dca47f489e1

See more details on using hashes here.

File details

Details for the file testing.mysqld-1.2.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for testing.mysqld-1.2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5771691158a8ac9255eb6c219b4a4e5043daab5ee58090a0a2e72db885410b81
MD5 4577c71456253e02af8886303a9ef836
BLAKE2b-256 fa7bb5b8daeeb922a2a9de0a7ca93169b4cd754dd217cfca99cc1715d748f969

See more details on using hashes here.

Supported by

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