Skip to main content

Helper to integrate external tests with python unittests.

Project description

Runs tests provided by an external command from Python’s unittest.TestCase.


gocept.exttest provides one public function, makeSuite, which returns a unittest.TestSuite and takes a single argument: the name of the external binary to run. (Any additional arguments will be passed to the external command as command-line parameters.)

Here’s a simple example:

import gocept.exttest
def test_suite():
    return gocept.exttest.makeSuite(
        'bin/external_test_runner', '--some-arg', '--another-arg')

makeSuite calls the external command to ask for a list of test cases and test functions (see below for the exact protocol), and returns a TestSuite of TestCase objects that contain corresponding test methods. Each test method will call the external command to run its test, and converts the results returned by the external command to the conventions of the unittest module (e.g. raises AssertionError for failed tests, etc.).


The external command needs to understand two command line parameters: --list and --run <test-specification>:

--list must return a list of available test cases and test functions formatted as JSON:

$ bin/external_test_runner --list
[{"case": "MyExternalTestCase",
  "tests": ["test_one", "test_two"]}

--run is used to run one specific test, returning the results formatted as JSON:

$ bin/external_test_runner --run MyExternalTestCase.test_two
[{"name": "MyExternalTestCase.test_two",
  "status": "FAIL",
  "message": "Test failed.",
  "traceback": "..."}]

NOTE: The custom JSON format for test results was chosen for simplicity when integrating with JavaScript (see below); we’ll have to evaluate whether the commonly used XML format from JUnitReport could be used instead.

If neither --list nor --run is given, the external command should run all tests:

$ bin/external_test_runner
[{"name": "MyExternalTestCase.test_one",
  "status": "SUCCESS",
  "message": "Test passed."},
 {"name": "MyExternalTestCase.test_two",
  "status": "FAIL",
  "message": "Test failed.",
  "traceback": "..."}]

Example: JavaScript

Running tests

We built gocept.exttest to integrate javascript unittests with python unittests. We’ve decided to use Jasmine as the javascript unittest framework, running under node.js via jasmine-node. (In order to use jasmine with gocept.exttest, we extended jasmine-node to support the --list / -run arguments and the JSON output format.)

In your buildout environment, install node.js and jasmine-node like this:

parts =

recipe = gp.recipe.node
npms = ${buildout:directory}/../jasmine-node
scripts = jasmine-node

recipe = zc.recipe.testrunner
eggs = your.package
environment = env

jasmine-bin = ${buildout:directory}/bin/jasmine-node

You need to checkout the jasmine-node fork from until the changes are merged upstream. (In the example, ${buildout:directory}/../jasmine-node is used for its location.)

Writing tests

For example, let’s say the javascript tests should reside in your.package.tests. jasmine-node supports tests written in both JavaScript and CoffeeScript (by specifying the --coffee command-line parameter), and requires test files to have _spec in their name.

An example test might look like this (please refer to the Jasmine documentation for details)

require 'my_app.js'

describe 'MyApp', ->
 it 'has read Douglas Adams', ->
   expect(new MyApp().calculate_the_answer()).toEqual(42)

Then wire up the tests as follows (the path to the external command is passed to the tests via an environment variable):

import gocept.exttest
def test_suite():
   return gocept.exttest.makeSuite(
       pkg_resources.resource_filename('your.package', 'tests'))


The source code is available in the mercurial repository at

Please report any bugs you find at


1.1 (unreleased)

  • Nothing changed yet.

1.0 (2012-01-24)

  • Reworked documentation.

0.1.4 (2012-01-20)

  • Package description.

0.1.3 (2012-01-20)

  • Improved the docs.

0.1.2 (2012-01-19)

  • Repair broken release (again).

0.1.1 (2012-01-19)

  • Repair broken release (0.1).

0.1 (2012-01-19)

  • 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

gocept.exttest-1.0.tar.gz (7.8 kB view hashes)

Uploaded Source

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