Package: integrate
The usual testing frameworks you can find for Python are so-called unit-testing-frameworks. As this collides with some goals of integration testing this framework was built.Changelog1.0.0First release, supports Python >= 3.31.1.0Backport to work on Python 2.7If you want to use Python 3 use at least 3.31.2.0Bugfix: Python 2 issue (Re #4)Ignore Test Base classes (Thanks withrocks:https://github.com/withrocks)Testrunner.run() now returns stats (Thanks nooploop:https://github.com/nooploop)1.3.0Add optionalargs=torun()- function (Thanks kensthilaire:https://github.com/kensthilaire)What’s the difference between integration testing and unit-testing?In unit testing you should only test the smallest possible thing in your application (or library) and all test should be independent and the ordering of tests is not of particular interest. To make that possible it is very common to stub or mock data models or other external dependencies and only test the functionality of your data transforms. You define fixtures and setup and teardown functions to prepare the environment for a unit test and destroy that environment immediately after running the test.Integration testing tests the complete system and has no direct influence on the data in the system so naturally the ordering of tests matter and tests may have dependencies (one test creates a DB record which another one modifies, etc.)As you should test one thing in an unit-test only, you should only use a single assert in a unit test. The default behaviour of most assert methods in unit-testing-frameworks is to raise an exception. This means everything after the failed assert is skipped and the test is marked as failed. In integration-testing you probably want to check multiple things at once and get a detailed error report which checks failed exactly.What does this framework better than others?You have full control over which tests run in what order (if you want)You can mark tests as dependent on others, so they will be skipped when a dependency failsYou can log as many errors as you want in a single test. Every error saves a stack trace and the error message for further debuggingThe test runner is very flexible (Your python files that contain the tests do not need to be in python modules)How to use it aka QuickstartInstall:pip install integrateWrite a test case class:from integrate import TestCase, test

class Test(TestCase):
        "Simple test case"

        @test(skip_if_failed=["other_test"])
        def simple_test(self, check):
                check.equal(1,2)

        @test()
        def other_test(self, check):
                "Always failing test"
                check.fail("Always fails")Write a test-runner (we assume you put the test case intotests/test.py):#!/usr/bin/env python

from integrate import TestRunner
TestRunner(dirs=["tests"], pattern="*.py").run()Make it executable and run it (or run withpython testrunner.py):chmod a+x testrunner.py
./testrunner.pyShort documentationAll tests have to be in a class that is derived fromTestCase, you may put anything in that class that you want, functions that should be called by the test runner have to be decorated with@test().TestCaseclassTheTestCaseclass is the workhorse of the integrate framework. It has some functions you may override in a subclass in addition to adding test functions:def setup_all(self):This function is run at the beginning of the test case class before any test is starteddef teardown_all(self):This function is run at the end of the test case class after all tests have finisheddef setup_test(self):This function is run before each test in the test casedef teardown_test(self):This function is run after each test in the test caseYou can run the test case class by it’s own by callingYourTestCase().run()or rely on the test runnerThere are some interesting initialization parameters:verbosity, how verbose the test output should be (min: 0, max: 2, default: 2)checker, whichChecksubclass to use, usually you will use the defaultCheckclass, but you may extend that to add methods to thecheckobject all tests receive@testdecoratorAll functions that should be picked up by theTestCaseclass have to be decorated with@test()(notice the parentheses!), the decorator has some optional parameters:skipboolean, defaults toFalse, set toTrueto skip a testskip_if_failedlist of strings, names of test functions that have to succeed (not fail or be skipped) in order for this function to run, defaults to an empty listdependslist of strings, names of test functions that should be run before this function, defaults to an empty listexpect_failboolean, set to true if you expect this test to fail (just for logging purposes)The test functions have 2 parameters:selfandcheck, for the description ofcheckread on.CheckclassAll errors that surface in a test should be found and logged by an instance of theCheckclass. You may subclass this class to add additional checker functions and insert it into theTestCaseorTestRunnerinitializer.The assertion API looks like the following, if there is amessageparameter it usually is optional and may be left out. User messages are prepended to an error message:equal(a, b, message=None)Check if two values are equalnot_equal(a, b, message=None)Check if two values are not equalis_none(a, message=None)Check if a value is Noneis_not_none(a, message=None)Check if a value is not Noneis_true(a, message=None)Check if a value is Trueis_false(a, message=None)Check if a value is Falsefail(message)Just log an error messageraises(exception_type, function, *args, **kwargs)Check if a function raises a specified exception type, args and kwargs are forwarded to the functiondoes_not_raise(function, *args, **kwargs)Check if a function does not raise an exception, args and kwargs are forwarded to the functionAll check functions should returnTrueif the check succeeded andFalseif it failed if they don’t have to return any other result (like theraisesanddoes_not_raisefunctions which return the result of the function orNone)Exceptions in test functions will still cancel the test function and log the exception to the error log if you don’t wrap it with araises()call. The traceback of an exception caught by the toplevel will be not of much use though if you can’t pinpoint the location based on the exception type. If you just want to catch all exceptions usecheck.raises(Exception, myFunc, "myParam")For extending theCheckclass there is a, rather small, extension API:log_error(error, message, detail=None, strip=4)Use this function to add an error to the list, a corresponding stack trace is appended automatically. Theerrorparameter is a textual one line description of the error, themessageparameter is a user message. Use thedetailparameter to give a detailed error description if needed. Only modify thestripparameter if your stacktrace gets entries after the error location in the test, by default it strips the last 4 stack frames as these are in the testing framework and just clobber the stack traces.error_message()Use this for debugging, this function joins all error messages into one stringTestRunnerclassTheTestRunnerclass is the entry point for automatically discovering tests in a project and running them. It has some initialization parameters:verbosityverbosity of test output (min: 0, max: 2, default: 2)dirslist of directories to scan for tests, defaults to current directory. Directories are scanned recursively.patternfile name pattern to search (argument tofnmatch) defaults to the python best practice*_test.pycheckertheChecksubclass to send to the tests, if you have subclassed theCheckclass put your class here, defaults to the unmodifiedCheckclassTo start the tests instanciate the test runner and call therun()function:from integrate import TestRunner
TestRunner().run()If you want to run just some tests of your test suite you may either run the tests directly by callingrun()on theTestCasesubclass or by supplying a filter to therun()function of the test runner like so:TestRunner().run(only='special.')This example would only run tests which have a module name that starts withspecial.the module names are generated by replacing all slashes of the python file path with a dot and removing the.pyextension.A test file that is stored in the pathspecial/tests/runme.pywill get a module name ofspecial.tests.runme.If you only want to look at what the Test runner would actually do use theplan()function, this just displays a list of test that would be executed and the order of execution instead of really running the tests. It has the same parameters as therun()function.