Skip to main content

dbfixtures plugin for py.test.

Project description

py.test clean fixtures: mysql, redis, mongo, rabbitmq

Starts specific database deamon and cleanup all data produced during tests.

Install

$ pip install pytest-dbfixtures

How to use

def test_using_mysql(mysqldb):
    mysqldb.query("SELECT CURRENT_USER()")


@pytest.fixture(scope='session')
def some_session_fixture(mysqldb_session):
    mysqldb_session.query("CREATE DATABASE xyz")
    rows = mysqldb_session.query("USE xyz")


def test_using_redis(redisdb):
    redisdb.set('woof', 'woof')
    woof = redisdb.get('woof')


def test_using_mongo(mongodb):
    db = mongodb['test_database']
    db.test.insert({'woof': 'woof'})
    documents = db.test.find_one()


def test_using_rabbit(rabbitmq):
    channel = rabbitmq.channel()

Use your own configure files

Of course you can! Below you can see example configs.

  • pytest_dbfixtures/dbfixtures.conf

  • pytest_dbfixtures/redis.conf

  • pytest_dbfixtures/mongo.conf

  • pytest_dbfixtures/rabbit.conf

If you want to use your own configs pass them as arguments to py.test.

Examples:

py.test --dbfixtures-config my-dbfixtures.conf

py.test --dbfixtures-config my-dbfixtures.conf --mongo-config my-mongo.conf

py.test --redis-config my-redis.conf
py.test --rabbit-config my-rabbit.conf

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

pytest-dbfixtures-0.3.8.14.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file pytest-dbfixtures-0.3.8.14.tar.gz.

File metadata

File hashes

Hashes for pytest-dbfixtures-0.3.8.14.tar.gz
Algorithm Hash digest
SHA256 6b34924b5e5771e3378ac1a3666b9c4790ab55435973ba74ada9bb829589e8de
MD5 84b54a0e5c36e808ee8f300075f91cdc
BLAKE2b-256 90e60f150b6560b9a713973fdbbec313980323482b247ac4c2226abac0ef0ac8

See more details on using hashes here.

Supported by

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