Skip to main content

Python unit test framework, an alternative to unittest.

Project description

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.

Differences From PyUnit (unittest)

  • Test identification by decorators

  • Module level tests

  • Simplified suite creation and execution
    • No calling or invoking a test runner

    • Create suites with a single keyword argument, not a separate object

  • Eval functions

  • 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

Coming soon

  • Test discovery

  • Context manager for assertRaises

  • Command-line single test case/class execution

  • Multi-suite tests

  • Custom printer modules

  • Python 3 support

Documentation

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. 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.

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 *

@Test
def atest():
        assert_true(True)

Test expecting an error:

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

@Test(expected=ValueError)
def tester():
        assert_equal(int("4.0"),4)

Using an instance variable:

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

@TestClass
class Class1:
        @Before
        def setup():
                this.num = 4

        @Test
        def test():
                assert_equal(this.num,4)
                this.num += 1

        @After
        def teardown():
                assert_equal(this.num,5)

unittest basic example:

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

@TestClass
class TestSequenceFunctions:
        @Before
        def setUp():
                this.seq = range(10)

        @Test
        def test_shuffle():
                # make sure the shuffled TestSequenceFunctions.sequence does not lose any elements
                random.shuffle(this.seq)
                this.seq.sort()
                assert_equal(this.seq, range(10))

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

        @Test
        def test_choice():
                element = random.choice(this.seq)
                assert_true(element in this.seq)

        @Test
        def test_sample():
                assert_raises(ValueError, random.sample, this.seq, 20)
                for element in random.sample(this.seq, 5):
                        assert_in(element,this.seq)

Contact Me

If you have any questions or comments, find any bugs, or wish to make any feature requests, shoot me an email at pyinq.test@gmail.com. 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.

Project details


Download files

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

Source Distributions

PyInq-0.1.0.zip (41.1 kB view hashes)

Uploaded Source

PyInq-0.1.0.tar.gz (19.4 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