Zope testing helpers

6.1 · active · verified Thu Apr 16

Zope.testing is a foundational Python package providing a suite of testing frameworks for Zope applications, supporting both doctest and unittest paradigms. It includes a flexible test runner (`zope.testrunner`), along with specialized utilities for test environment cleanup (`zope.testing.cleanup`), HTML form parsing for functional tests (`zope.testing.formparser`), robust logging support (`zope.testing.loggingsupport`), and streamlined setup/teardown automation (`zope.testing.setupstack`). The current version is 6.1, and its release cadence typically aligns with the broader Zope project, seeing updates roughly every 2-6 months.

Common errors

Warnings

Install

Imports

Quickstart

Zope.testing is primarily used via the `zope-testrunner` command-line script after installation. This script automatically discovers tests defined in `unittest.TestCase` classes (in files matching `test_*.py` within `tests/` subpackages) and doctests (in `.txt` files or docstrings). For project setup, ensure your package includes a `tests` directory with test modules.

import unittest
from zope.testing.testrunner.runner import Runner

class MyTests(unittest.TestCase):
    def test_example(self):
        self.assertTrue(True)

# To run tests programmatically, typically you'd use the command line script
# or a simple test discovery setup. The zope-testrunner script is often preferred.
# Example command line usage for a project with tests in 'my_package/tests/test_*.py':
# zope-testrunner --test-path=my_package --tests-pattern='^test_.*\.py$'

# Example of programmatic runner usage (advanced/specific scenarios):
# from unittest import TestSuite, makeSuite
# suite = TestSuite()
# suite.addTest(makeSuite(MyTests))
# runner = Runner(args=[], found_suites=[suite])
# succeeded = runner.run()
# if not succeeded:
#    print("Tests failed!")

view raw JSON →