Test Anything Protocol (TAP) tools for Python
tappy (installed as `tap-py`) is a set of Python tools designed for working with the Test Anything Protocol (TAP). It enables Python's unittest framework to produce TAP-formatted output, facilitating integration with other testing systems that consume TAP. The library is currently at version 3.2.1 and maintains an active, though irregular, release cadence to support new Python versions and address bug fixes.
Common errors
-
ModuleNotFoundError: No module named 'tap.yaml'
cause Attempting to use TAP version 13 features (like YAML blocks) without installing the optional 'yaml' dependencies.fixInstall `tap-py` with the `yaml` extra: `pip install tap-py[yaml]`. -
AttributeError: module 'tap' has no attribute 'TAPTestRunner'
cause Incorrect import path for `TAPTestRunner`. It resides in the `tap.runner` submodule.fixChange your import statement from `from tap import TAPTestRunner` to `from tap.runner import TAPTestRunner`. -
My tests run, but I don't see any TAP output.
cause The default `unittest.TextTestRunner` is being used, or the `python -m tap` command-line entry point was not utilized. `tap-py` provides specific runners to generate TAP output.fixTo get TAP output, either use `from tap.runner import TAPTestRunner` in your test runner setup, or simply execute your tests using `python -m tap` in the directory containing your tests.
Warnings
- breaking Version 3.0 dropped support for Python 2. This was a significant change, requiring users to migrate to Python 3.
- breaking In version 2.0, the `nose` and `pytest` plugins were removed from `tap-py` and moved to separate distributions (`nose-tap` and `pytest-tap`).
- gotcha Older Python versions are routinely dropped. As of version 3.2, Python 3.6, 3.7, and 3.8 are no longer supported.
Install
-
pip install tap-py -
pip install tap-py[yaml]
Imports
- TAPTestRunner
from tap import TAPTestRunner
from tap.runner import TAPTestRunner
Quickstart
import unittest
from tap.runner import TAPTestRunner
class MyTests(unittest.TestCase):
def test_example_success(self):
self.assertTrue(True)
def test_example_failure(self):
self.assertEqual(1, 2)
if __name__ == '__main__':
# Using the TAPTestRunner to get TAP output
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MyTests))
runner = TAPTestRunner()
runner.run(suite)
# Alternatively, for discovery (similar to 'python -m unittest discover')
# and direct TAP output to console from tests in current directory:
# import os
# os.system('python -m tap')