Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Managed test instances for integration tests

Project description

testinstances is a set of managed instance wrappers to make integration testing with redis and mongodb easier. If you have the binaries on your path, it can handle creating and destroying sandboxed instances for you to test with.


The API is straightforward and easily embedeed in setup/teardown functions. It also automatically returns a connection to the instance.:

import unittest

from testinstances import RedisInstance

class TestSomeJunk(unittest.TestCase):
  def setUp(self):
    # Set up an instance on port 12345
    self.redis = RedisInstance(12345)

  def tearDown(self):

  def test_stuff(self):
    self.redis.conn.set('foo', 'bar')
    self.assertEqual(self.redis.conn.get('foo'), 'bar')

Or, if you wanted to be fancy and avoid the process creation/termination cost for every test case:

import unittest

from testinstances import MongoInstance

class TestSomeJunk(unittest.TestCase):
  def setUpClass(cls):
    # Set up an instance on port 12345
    cls.mongo = MongoInstance(12345)

  def tearDownClass(cls):

  def setUp(self):
    # All instance types implement ``flush``

  def test_stuff(self):
    collection = self.mongo.conn['someDB']['someCollection']
    collection.insert({'foo': 'bar'})
    self.assertEqual(collection.find({'foo': 'bar'}).next()['foo'], 'bar')


To run the tests you need to install all of the databases the tests run:

For Debian/Ubuntu:

$ sudo apt-get install redis-server mongodb-server

For OSX:

$ sudo brew install redis mongodb

Then you just run tox.


  • New Instance Kinds
    • Kafka
    • Zookeeper
  • Documentation and ReadTheDocs
  • Travis-CI

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
testinstances-0.3.0.tar.gz (6.7 kB) Copy SHA256 hash SHA256 Source None Oct 19, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page