Skip to main content

Python unit test framework, an alternative to unittest.

Project description

Find the Spanish translation of this page here:

PyInq is a Python unit testing framework created in the tradition of the xUnit family. Specifically, it draws its influence from JUnit and PyUnit (unittest).

The bulk of PyInq’s functionality was influenced by PyUnit. However, Java coders will recogize the use of decorators for test identification from JUnit 4. Selenium users will recogize PyInq’s suite of “eval” functions; they were influenced by Selenium’s “verify” functions.

Version 0.2 adds a much needed feature: test discovery. Specify a root directory, and PyInq will discover and execute all tests found beneath it. Best of all, it can be run from either the command line, or programmatically through an API.

Differences From PyUnit (unittest)

  • Test identification by decorators
  • Module level tests
  • Suite support
    • Simplified creation and execution
    • No calling or invoking a test runner
    • Create suites with a single keyword argument, not a separate object
  • Eval functions (passive asserts)
  • Detailed, color coded output
    • For each test, prints the result of each assert and eval statement
    • Color coded based on result
  • Pythonic naming

Other Notable Features

  • Test fixtures
    • At test, class, module, and suite level
  • Expected exceptions
  • Conditional skips
  • Output to command line (CLI) or an HTML file
    • CLI defaults to color output in Windows console and Linux bash
    • CLI defaults to black and white in any other system
  • Command line test module/suite execution
  • Test discovery

Coming soon

  • Context manager for assertRaises
  • Command-line single test case/class execution
  • Multi-suite tests
  • Custom printer modules
  • Python 3 support


I have not yet had the chance to write up much documentation. It’s high on my TODO list as undocumented projects can be aggrevating to work with. I intend to produce a basic guide to using PyInq, as well as code comments and docstrings.

For now, there is basic documentation in the download. In the docs folder, there is a file called “reference.txt”. This assumes knowledge of unit test frameworks, and serves as a basic reference for what PyInq includes, and how to use it. The other is a directory called examples, which contains a number of tests that exercise various aspects of PyInq. I’ve tried to name them in a straightforward manner to enable them to giude your usage of this package.

Additionally, I’ve included a section on test discovery and some basic examples below.

Basic Examples

Simply run the code as is to try any of these examples for youself

A single module level test:

from pyinq.asserts import *
from pyinq.tags import *

def atest():

Test expecting an error:

from pyinq.asserts import *
from pyinq.tags import *

def tester():

Using an instance variable:

from pyinq.asserts import *
from pyinq.tags import *

class Class1:
        def setup():
                self.num = 4

        def test():
                self.num += 1

        def teardown():

unittest basic example:

from pyinq.asserts import *
from pyinq.tags import *
import random

class TestSequenceFunctions:
        def setUp():
                self.seq = range(10)

        def test_shuffle():
                # make sure the shuffled TestSequenceFunctions.sequence does not lose any elements
                assert_equal(self.seq, range(10))

                # should raise an exception for an immutable TestSequenceFunctions.sequence
                assert_raises(TypeError, random.shuffle, (1,2,3))

        def test_choice():
                element = random.choice(self.seq)
                assert_true(element in self.seq)

        def test_sample():
                assert_raises(ValueError, random.sample, self.seq, 20)
                for element in random.sample(self.seq, 5):

Test Discovery

Test discovery is a method for finding tests beginning at a specific root folder. The program will walk down each Python package in the folder structure until it has nowhere else to go. If any files in the package contain PyInq tests, they will be properly detected and executed.

The main way to use it is invocation from the command line, like so:

python -m pyinq discovery <root>

Output is the same as when executing a single file, with the addition of a tag indicating which module a set of tests belongs to.

You may also choose to invoke test discovery via the API. If you do, you will be given a TestSuite object, which is executable. A sample of how to use it appears below:

from pyinq import discover_tests

suite = discover_tests('examples')
if suite:

Contact Me

If you have any questions or comments, find any bugs, or wish to make any feature requests, shoot me an email at I am especially hoping to receive bug reports, for although I am unaware of any bugs, fresh sets of eyes have a better chance of finding what I missed.

Also, I will be setting up a separate web page and public GitHub repo for this project very soon. I will post those links here once they are ready.

Change Log

v0.2.0, March 3, 2013
  • Test discovery (command line and API)
  • Made test discovery a subcommand, with its own special command line arguments
  • Test execution through Python interpreter (“python -m pyinq”)
  • Implicit class instance now “self” (was “this”)
  • @test’s expected error argument now “expect” (was “expected”)
  • Empty classes no longer listed in test report
  • Disable auto-execution in code
  • Refactored test fixture and test data classes
    • Treating test object as a string yields test structure within that object
  • Rebuilt suite collection
  • Rebuilt test registration
v0.1.1, July 26, 2012 –
  • Renamed each tag to begin with a lower case letter.
  • Fixed a bug in the eval example.

v0.1.0, July 23, 2012 – Initial release.

Project details

Release history Release notifications

History Node


This version
History Node


History Node


History Node


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
PyInq-0.2.0.tar.gz (25.4 kB) Copy SHA256 hash SHA256 Source None Jun 27, 2013 (52.4 kB) Copy SHA256 hash SHA256 Source None Jun 27, 2013

Supported by

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