This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

An experimental behavioral framework inspired from rspec.

Project Description


A Behavior Driven Development or BDD framework inspired off of RSpec. The reason of BDD over TDD is out of scope of this project. But this framework is simply a way to try and encourage me to do more testing.

It is worth noting the development version breaks the existing API.


To install, use pip or easy_install:

pip install describe

Then you can import it:

from describe import Spec, Value, Mock # classes
from describe import arg, repository   # submodules



Then you can import the library for use in unittest or nose. The core feature is the Value object:

from describe import Value

Use this Value class to wrap values you want to set expectations. Here’s some API examples until I get proper documentation:

# self.assertEquals(9, 9)
Value(9).should == 9

# self.assertAlmostEqual(5.0-4.0, 1.0)

# self.assertIn(3, (2,3,4))

# self.assertNotIn(5, (2,3,4))

# self.assertFalse(False)

# self.assertTrue(isinstance((), tuple))

# self.assertEqual(len(range(5)), 5)
# '.elements' is optional

# self.assertGreaterEqual(len(range(5)), 4)


Mocks are used to abstract out classes that are not being tested. They can customized to return specific results and logs all operations done to it for verification later on. The mock API wraps the voidspace mock library. Feel free to use it directly instead of this API.

describe.Mock supports a few operations:

  • Mock.should_access property - Allows you to set expectations of method calls and attribute accesses.
  • Mock.should_not_access(attr_name) - Allows you to set expections of attributes not getting accessed.
  • Mock.verify() - Verifies all the expectations, throwing AssertionErrors if need be.
  • Mock.reset_mock() - clears the access log, you should never really use this directly.

All other attributes get directed to the voidspace mock object. A basic example:

# create the mock
from describe import Mock
m = Mock()

# set an expectation on what will be performed on the object and it's response

# run it
m.upper() # => 'FOO'

# verify that the operations were executed

# if you want to invoke any operations on the mock object (and not the API), get the
# voidspace mock object via the mock attribute:
m.mock.verify() # => 'bar'

These expectations expect the function prototype you give it:

m.should_access.rjust(5).and_return('     ')
m.rjust()  # => None - prototype does not match.
m.rjust(5) # => '     '
m.verify() # will raise AssertionError because m.rjust() was called

Keyword arguments work just as well as args. There are several special arguments you can give for special operations.

args.ANYTHING accepts any arguments as valid, including no arguments:

from describe import args
m.should_access.rjust(args.ANYTHING).and_return('anything works')
m.rjust('foo', 'bar') # => 'anything works'

args.ANY_ARG accepts any single argument:

from describe import args
m.rjust() # => None - is not one argument
m.rjust(3) # => 4

Other special args include:

  • arg.ARGS - any non-keyword arguments
  • arg.KWARGS - any keyworded arguments
  • arg.an_instance_of(type) - any argument whos value matches the given type
  • arg.regexp - alias for arg.an_instance_of(type(re.compile(”))) for a regular expression type.
  • arg.includes_pair(key, value) - any argument who has a key and associated value.
  • arg.contains(item, *items) - any keys or items in the given list or dictionary.
  • arg.duck_type(*attributes) - any object that has all of the given attributes

You can also set expectations for getter properties:

m.score # => 23

Calling verify on every mock object you create is tiresome. Fortunately, each mock is added to a registry when instantiated. By default, they are added to the describe.mock.repository.default repository. You can call verify() on the repository to verify all mocks in it:

# create mocks:
from describe import Mock, Value
from describe.mock import repository
for i in range(5):
  m = Mock()
  Value(m.lower()).should == 'bar'

repository.default.verify() # will verify all mock objects we created above


The entire purpose of behavior driven development, is to remap the testing-based terminology to more specification driven ones. The Spec class is an alternative to unittest.TestCase, but you’ll need nose / sniffer to reap all the benefits.

Currently Specs inherit unittest.TestCase:

from describe import Spec, Mock
from describ.args import *
class DescribeRSpecExpectingArguments(Spec):
    def before(self):
        self.m = Mock()

    def it_should_expect_arguments(self):

    def it_should_expect_arguments_with_count(self):

    def it_should_expect_no_arguments(self):

    def it_should_expect_any_arguments(self):

Then use the \(SpecPlugin\) for nose to run the specs, or run describe.main program.

Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
describe-0.1.2.tar.gz (27.5 kB) Copy SHA256 Checksum SHA256 Source Feb 1, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting