Testing¶
The source code distribution of the relayr Python library contains a testsuite that can be run after downloading the full code archive. It is not installed together with the Python package itself, but needs to be run from the unarchived code distribution. This has been tested mainly on Linux and OS X, and to some degree on a Raspberry Pi running Rasbian and a WRTnode running OpenWRT.
Testing on a single Python version¶
The test suite is located inside the tests subdirectory
and can be run using the PyTest framework which, unlike the unittest
framework, does not require writing much boilerplate code. This allows, among
other things, reusing single test snippets more easily outside of the test suite.
To run the tests you don’t even need to have PyTest installed, since the
archive contains a file named runtests.py which is essentially a minimized
version of PyTest itself (generated by the respective py.test tool).
Running the full test suite from the main directory of the unarchived code distribution is as simple as this:
$ python runtests.py tests
If you have PyTest installed (pip install pytest will do) you can
ignore the runtests.py file:
$ py.test tests
In both cases the output should be something like this, when everything runs
correctly (the s indicates a skipped test, here because of platform
limitations):
=========================== test session starts ============================
platform darwin -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4
collected 49 items
tests/test_anonymous.py ............
tests/test_bluetooth.py ss
tests/test_config.py .
tests/test_data_access.py ...ss.
tests/test_registered.py ............................
================== 45 passed, 4 skipped in 103.02 seconds ==================
Of course, you can add more verbosity, run selected test modules or methods if desired and much more. Please see the PyTest documentation for more information!
Testing on multiple Python versions¶
One other, and significant, advantage of using the PyTest framework is being able
to run the tests easily over a whole range of Python versions. A nice tool for
automating this is tox, which can be easily installed with pip install tox.
Given a short configuration file named tox.ini like the one provided in the
top-level directory of this package one can simply call tox to run the test
suite over multiple versions of Python automatically (below only the summary of
a run over four versions is shown):
$ tox
=========================== test session starts ============================
[ ... detailed output skipped here ... ]
================== 45 passed, 4 skipped in 103.02 seconds ==================
_________________________________ summary __________________________________
py26: commands succeeded
py27: commands succeeded
py33: commands succeeded
py34: commands succeeded