Running the tests

Once you have written some tests using pyqcy, you would most likely want run them.

If you already have a test suite of different kinds of tests for your projects (typically at least unit tests), you probably want to integrate pyqcy properties into that.

Alternatively, properties can be also verified using a built-in, standalone test runner.

Test runner

pyqcy includes a readily available test runner which can be used to run verification tests for all properties defined within given module. For it to work, you just need to include a traditional if __name__ == '__main__': boilerplate which calls pyqcy.main():

from pyqcy import *

# ... define test properties here ...

if __name __ == '__main__':

This default test runner will go over all properties defined within this module, as well as all modules it imports, and execute tests for them. It is intentionally similar in usage to standard unittest.main and shares many parameters with the unittest runner (to the extent it makes sense for pyqcy tests, of course).

pyqcy.runner.main(module='__main__', exit=True, verbosity=2, failfast=False)

Built-in test runner for properties.

When called, it will look for all properties (i.e. functions with qc() decorator) and run checks on them.

Arguments are intended to mimic those from unittest.main(). Return value is the total number of properties checked, provided exit is False and program doesn’t terminate.

Integration with testing frameworks

If you are already using a unit testing framework, you can easily integrate pyqcy property tests into it.

For this, there is a TestCase class which is a descendant of the standard unittest.TestCase. Any test cases built upon it will be gathered and ran by pretty much any testing framework - be it unittest itself, nose, py.test, etc.

Therefore all we need to do is to put out properties inside a TestCase subclass:

from pyqcy import *

class Arithmetic(TestCase):
    def addition_on_ints(x=int, y=int):
        assert isinstance(x + y, int)
    def subtraction_on_ints(x=int, y=int):
        assert isinstance(x - y, int)

There is no need to rename the properties to start with test_ but we should retain the qc() decorator. We also don’t need to include any other methods that would explicitly run tests for our properties, as the base TestCase class will take care of it automatically.

class pyqcy.integration.TestCase(methodName='runTest')

unittest test case for pyqcy properties.

Properties defined here within subclasses of TestCase will be verified automatically as a part of standard unittest run. To define them, use the typical syntax with qc() decorator:

class Sorting(TestCase):
    '''Properties that must hold for a sorting.'''
    def sort_preserves_length(
        l=list_(of=int, max_length=128)
        assert len(l) == len(list(sorted(l)))
    def sort_finds_minimum(
        l=list_(of=int, min_length=1, max_length=128)
        assert min(l) == list(sorted(l))[0]

Since TestCase itself is a subclass of standard unittest.TestCase, it will be discovered by unittest.main(), nosetests or similar testing utilities.