{"id":8804,"library":"zope-testing","title":"Zope testing helpers","description":"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.","status":"active","version":"6.1","language":"en","source_language":"en","source_url":"https://github.com/zopefoundation/zope.testing","tags":["testing","zope","doctest","unittest","testrunner","functional-testing","cleanup","logging"],"install":[{"cmd":"pip install zope.testing","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required Python version for zope.testing 6.x series.","package":"Python","optional":false,"min_version":"3.10"},{"reason":"Optional dependency for zope.testing.setupstack.mock functionality.","package":"mock","optional":true},{"reason":"Optional dependency for subunit-based test output formatting.","package":"subunit","optional":true},{"reason":"Optional dependency for subunit-based test output formatting.","package":"testtools","optional":true}],"imports":[{"symbol":"Runner","correct":"from zope.testing.testrunner.runner import Runner"},{"symbol":"cleanup","correct":"from zope.testing.cleanup import cleanup"},{"symbol":"InstalledHandler","correct":"from zope.testing.loggingsupport import InstalledHandler"},{"symbol":"setupstack","correct":"import zope.testing.setupstack"},{"symbol":"doctestcase","correct":"import zope.testing.doctestcase"},{"symbol":"renormalizing","correct":"import zope.testing.renormalizing"}],"quickstart":{"code":"import unittest\nfrom zope.testing.testrunner.runner import Runner\n\nclass MyTests(unittest.TestCase):\n    def test_example(self):\n        self.assertTrue(True)\n\n# To run tests programmatically, typically you'd use the command line script\n# or a simple test discovery setup. The zope-testrunner script is often preferred.\n# Example command line usage for a project with tests in 'my_package/tests/test_*.py':\n# zope-testrunner --test-path=my_package --tests-pattern='^test_.*\\.py$'\n\n# Example of programmatic runner usage (advanced/specific scenarios):\n# from unittest import TestSuite, makeSuite\n# suite = TestSuite()\n# suite.addTest(makeSuite(MyTests))\n# runner = Runner(args=[], found_suites=[suite])\n# succeeded = runner.run()\n# if not succeeded:\n#    print(\"Tests failed!\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python interpreter to 3.10 or a newer supported version.","message":"Zope.testing 6.x and newer officially dropped support for Python 3.9. Ensure your environment uses Python 3.10 or later.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Update `zc.buildout` to version 5+ if used, and review package configurations for PEP 420 compatibility. Manual adjustments to `__init__.py` files for namespace packages might be required if not using modern tools.","message":"Starting with Zope 6.0 (which zope.testing aligns with), namespace package declarations switched from the older `pkg_resources` style to PEP 420 native implicit namespaces. This change may cause import issues in certain add-ons or complex package structures built with older tools like `zc.buildout` < 5.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Migrate any direct usage of `zope.testing.doctest` to the standard `import doctest` and adjust test code accordingly. The `zope-testrunner` will handle standard doctests correctly.","message":"The `zope.testing.doctest` module is deprecated. The `zope.testrunner` has been modified since version 3.9.0 to use Python's standard `doctest` module. Directly importing `zope.testing.doctest` for new code is discouraged.","severity":"deprecated","affected_versions":"All versions (deprecation noted since 3.9.0)"},{"fix":"Use the `zope-testrunner` command-line script directly, or integrate with `tox` for test execution as shown in the library's development setup.","message":"The `setup.py test` command, historically used to run tests, is no longer supported by modern `setuptools` versions and has been removed from `zope.testrunner` in version 8.2 and later.","severity":"breaking","affected_versions":"zope.testrunner 8.2+"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `zope.testing` is installed: `pip install zope.testing`. If using virtual environments, activate the correct environment. For buildout-based projects, ensure `zope.testing` is properly listed in `eggs`.","cause":"The `zope.testing` package is not installed in the current Python environment or the Python path is misconfigured.","error":"ImportError: No module named zope.testing"},{"fix":"Review the doctest example; if an exception is expected, ensure no extraneous `print` statements precede it in the test block. For modern usage, rely on the standard `doctest` module's behavior for output matching.","cause":"In older versions, or when directly using `zope.testing.doctest`, if a doctest block included print statements immediately before raising an exception, the printed output might interfere with the expected output matching, leading to failure.","error":"Doctest output does not match expected output (especially with exceptions/prints)"},{"fix":"Ensure your test files are named `test_*.py` and located in a `tests/` subdirectory of your package. Run the test runner with `zope-testrunner --test-path=./path/to/your/package`. For doctests, ensure they are `.txt` files in `tests/` or explicitly referenced.","cause":"The `zope-testrunner` script was run without specifying the correct `--test-path` or the test files do not follow the expected naming convention (`test_*.py` in `tests/` subpackages or explicitly listed doctests).","error":"zope-testrunner does not find tests"}]}