This project is no longer under development. Please see the fixture module (its successor) instead


testtools

Tools for controlling test environments.

It provides:

  • testtools.fixtures -- an abstract interface for installing and reading tabular data;
  • testtools.io -- tools for setting up and tearing down I/O environments;
  • and testtools.stubs -- a sparse set of tools for stubbing objects.

This package came to life while developing real test suites for applications and libraries, so nothing has been added here that wasn't necessary for some task or another.

In my own experience with testing, it pays to get as close to the real world as possible. I try to use stub or mock objects only as a last resort, for optimization, etc. Thus, the crux of this package is the fixtures module -- it provides the means to load mock data into a real database (or any storage medium).

Patches are welcome, preferably with tests ;) The current project is being trac'ed at http://testtools.python-hosting.com/

See docs on each individual module for examples and usage.

Easy Install

easy_install testtools

get the easy_install command

Download

Install

tar -xzf testtools-XX.tar.gz
cd ./testtools-XX
python setup.py test
sudo python setup.py install

Or, live dangerously

svn co http://svn.testtools.python-hosting.com/trunk testtools
easy_install ./testtools

Documentation

Browse the docstrings in the code for the latest ... or if you have pudge installed you can build the docs from source like so :

cd testtools
./bin/build_doc

Show me an example!

from decorator @with_fixtures here is a small example designed to run in nose:

>>> from testtools.fixtures import CsvFixture, with_fixtures
>>> class MyBooks(CsvFixture):
...     class meta:
...         filename = open('/tmp/testtools_example.csv', 'w')
...         data = (('lolita', {'title':'lolita'}),)
...         clean = True
...
>>> @with_fixtures(MyBooks)
... def test_with_books(fxt):
...     print fxt.lolita
...     # test something ...
...
>>> test_with_books()
<class 'Fixture.Values' dict(title='lolita') from module testtools.fixtures.fixtures>
>>>

Dependencies

When you install testtools, no dependencies are forced upon you since most of the code can be used with just the standard library. However, the easiest thing is to run python setup.py test and see if you get any import errors. If you want a head start here is a list of dependencies (probably incomplete) that you will need to run the full test suite.

Contribute

see TracGuide

Contact

You can create a ticket to report a bug or submit a patch. Comments / questions can be sent to <kumar dot mcmillan / gmail>

Does it work with Python 2.3?

errm, maybe. I had to install it on a 2.3 server once so I removed as much new 2.4 code as I could. But I don't actively run the test suite with python 2.3. I know for a fact that bgtests won't work because it imports subprocess.

Changelog

  • 0.7.8
    • bug fix: implemented a custom is_generator method for compatibility with nose 0.10
  • 0.7.7
    • FINAL testtools release. See fixture module (its successor)
    • TempIO resolves symbolic links for temp root
    • fixed bug in with_fixtures, for decorating generators
    • TempIO.putfile() now returns the absolute filepath that it created
    • removed testtools.bgtests module in lieu of the omnipotent buildbot
    • added mode keyword to TempIO.putfile()
  • 0.7.6.1
    • added deferred keyword to TempIO objects so they can put off destruction until atexit
  • 0.7.6
    • added mknewfile attribute to CsvFixture, a factory for creating file objects
    • added fixtures.metamethod decorator for creating callable meta attributes
    • fixed nose compatibility issues with decorator fixtures.with_fixtures
  • 0.7.5.1
    • tweaked the code so that fixtures.with_fixtures appeared in the docs (working around issues with pudge).
  • 0.7.5
    • re-implemented the inner Fixture.meta class to fix all the referencing problems that the old code had. This means subclassing Fixture descendants should be safe now.
    • added fixtures.with_fixtures, a decorator for instantiating a simple FixtureCollection and wrapping it around a standalone test function atomically.
    • added 'dialect' keyword to CsvFixture so that tab-separated fixtures can be done directly with this class.
    • interface change : using unknown meta attributes now raises TypeError when before these were silently ignored, producing much head-scratching.
  • 0.7.4
    • fixed bug in CsvFixture where its objects were inappropriately trying to load/reload in the registry.
    • improved stubs.mkinterface()
    • SOFixture now performs all saves in a kind of singleton transaction. You can disable this by setting autocommit=False in the fixture meta, however by default it will be in a transaction. You may have to turn this off for postgres since it seems to deadlock with complex foreign key inserts.
    • added config.set_debug_stderr()
  • 0.7.3
    • interface change : renamed fixtures.unload_fixtures() to fixtures.unregister_fixtures() since it doesn't actually unload
    • added cascade keyword to Fixture.clean() so one can disable the cleaning of fixtures down the foreign key line
    • added keyword dialect to storage.CsvStor
    • fixed major bug in fixtures related to caching datasets
    • fixed minor bugs in build_release, genfix, setup_devdist
  • 0.7.2
    • interface change : removed Fixture.load_one() because it can't be used on its own anymore (use Fixture.load() instead)
    • CsvFixture can figure out fields automatically now
    • XmlStor now makes a declaration
    • fixed bugs in FixtureCollection related to foreign key dependencies
    • Fixture.clean() raises an error now if the object is not cleanable (safety measure for foreign key cleaning)
    • fixed bgtests output for reliable analytics (stdout always on top of stderr)
  • 0.7.1
    • changed license from GPL to LGPL
    • bgtests fixes :
      • in run(), setup() will now be called while in the root of the package dir
      • fixed malformed rst in docs, added more examples
  • 0.7
    • first public release!
    • completely rewrote the fixtures interface -- made it more pythonic and solved a show-stopper in the first interface related to loading foreign-key-dependent fixtures
    • added bgtests
    • added primitive support for debugging
    • fixed bugs
  • 0.6
    • first draft of an acceptable interface for fixtures (now deprecated)
    • added IO tools
    • fixed bugs
  • 0.5
    • fixtures, still experimental
    • added stubs
  • 0.4
    • basic working interface for fixtures
  • pre-0.4
    • working with fixtures across a few projects, very experimental

Future

About Trac

For a complete list of local wiki pages, see TitleIndex.

Trac is brought to you by Edgewall Software, providing professional Linux and software development services to clients worldwide. Visit http://www.edgewall.com/ for more information.