Skip to main content

The zope.pytestlayer distribution

https://img.shields.io/pypi/v/zope.pytestlayer.svg https://img.shields.io/pypi/pyversions/zope.pytestlayer.svg https://github.com/zopefoundation/zope.pytestlayer/actions/workflows/tests.yml/badge.svg https://coveralls.io/repos/github/zopefoundation/zope.pytestlayer/badge.svg?branch=master

Integration of zope.testrunner-style test layers into the pytest framework

This package is compatible with Python versions 3.7 - 3.12 including PyPy3.

It was formerly known as gocept.pytestlayer.

Quick start

  • Make sure your test files follow the conventions of pytest’s test discovery

    In particular, a file named tests.py will not be recognized.

  • Add a buildout section to create the pytest runner:

    [buildout]
    parts += pytest
    
    [pytest]
    recipe = zc.recipe.egg
    eggs = zope.pytestlayer
           pytest
           <YOUR PACKAGE HERE>

zope.pytestlayer registers itself as a pytest plugin. This way, nothing more is needed to run an existing Zope or Plone test suite.

Advanced usage

Version 2.1 reintroduced fixture.create() to be able to define the name of the generated to pytest fixtures. So it is possible to use them in function style tests.

Example (Code has to be in contest.py!):

from .testing import FUNCTIONAL_LAYER
import zope.pytestlayer.fixture

globals().update(zope.pytestlayer.fixture.create(
    FUNCTIONAL_LAYER,
    session_fixture_name='functional_session',
    class_fixture_name='functional_class',
    function_fixture_name='functional'))

This creates three fixtures with the given names and the scopes in the argument name. The session and class fixtures run setUp() and tearDown() of the layer if it has not been run before while the function fixture runs testSetUp() and testTearDown() of the layer. The function fixture depends on the session one. The fixtures return the instance of the layer. So you can use the functional fixture like this:

def test_mymodule__my_function__1(functional):
    assert functional['app'] is not None

Not supported use cases

  • Inheriting from a base class while changing the layer. See commit f879f9e.

  • Mixing classes inheriting unittest.TestCase and a test_suite() function (e. g. to create a DocTestSuite or a DocFileSuite) in a single module (aka file).

    • This is a limitation of the pytest test discovery which ignores the doctests in this case.

    • Solution: Put the classes and test_suite() into different modules.

  • A doctest.DocFileSuite which does not have a layer is silently skipped. Use the built-in doctest abilities of pytest to run those tests.

Developing zope.pytestlayer

Author:

gocept, Godefroid Chapelle <gotcha@bubblenet.be>

PyPI page:

https://pypi.org/project/zope.pytestlayer/

Issues:

https://github.com/zopefoundation/zope.pytestlayer/issues

Source code:

https://github.com/zopefoundation/zope.pytestlayer

Current change log:

https://raw.githubusercontent.com/zopefoundation/zope.pytestlayer/master/CHANGES.rst

Change log for zope.pytestlayer

9.2 (2026-06-30)

  • Add compatibility for pytest >= 9.1, requiring at least that version.

9.1 (2025-12-03)

  • Add compatibility for pytest >= 9.

  • Add support for Python 3.13, 3.14.

  • Drop support for Python 3.9.

9.0 (2025-09-12)

  • Replace pkg_resources namespace with PEP 420 native namespace.

8.3 (2025-05-15)

  • Add support for Python 3.13.

  • Add support for pytest >= 8, requiring at least that version.

  • Drop support for Python 3.7, 3.8.

8.2 (2024-05-15)

  • Make tests compatible with pytest >= 7.3. (Caution: We do not yet support pytest >= 8)

  • Add support for Python 3.11.

  • Add support for Python 3.12.

  • Rename from gocept.pytestlayer to zope.pytestlayer.

8.1 (2022-09-05)

  • Ensure compatibility with pytest >= 7.1.3. .layered.LayeredTestCaseInstance now has to inherit from _pytest.unittest.UnitTestCase.

8.0 (2021-12-13)

  • Use GitHub actions as CI.

  • Add support for Python 3.9 and 3.10.

  • Drop support for Python 3.6.

  • Add a workaround for #4: Use gcoept.pytestlayer.doctest.DocTestSuite instead of doctest.DocTestSuite to circumvent the issue.

7.0 (2020-08-03)

Backwards imcompatible changes

  • Drop support for Python 2.7 and 3.5 and pytest < 5.0. (#8)

Features

  • Support pytest >= 6.0. (#8)

6.3 (2020-05-15)

  • Ensure compatibility with pytest > 5.4.2. We need a _explicit_tearDown on our LayeredTestCaseFunction now.

6.2 (2020-03-20)

  • Ensure compatibility with pytest > 5.4. We need a _needs_explicit_tearDown on our LayeredTestCaseFunction now.

6.1 (2020-02-20)

  • Fix tests to run with pytest >= 4.2.0.

  • Migrate to Github.

  • Do not break when rerunning a doctest using pytest-rerunfailures.

  • Add support for Python 3.8.

6.0 (2018-10-24)

  • Add support for Python 3.6, 3.7 and PyPy3.

  • Drop support for Python 3.4.

  • Fix tests to run with pytest >= 3.9.1.

  • Release also as universal wheel.

  • Update to new pytest fixture API to avoid DeprecationWarnings. (#10)

5.1 (2016-12-02)

  • Make installation process compatible with setuptools >= 30.0.

5.0 (2016-08-23)

  • Fix tests to pass if pytest >= 3.0 is used for testing.

4.0 (2016-04-27)

  • Support Python 3.4, 3.5 and PyPy.

  • Use tox as testrunner.

3.0 (2016-04-14)

  • Claim compatibility with py.test 2.9.x.

  • Drop Python 2.6 support.

2.1 (2014-10-22)

  • Update handling of keywords and doctest testnames for py.test-2.5. [wosc]

  • Re-introduce gocept.pytestlayer.fixture.create() method, to allow giving created fixtures a non-random name, so other fixtures can depend on them. [tlotze, wosc]

  • Generate session-scoped fixtures from layers in addition to class-scoped ones, if a session-scoped one is required somewhere, the class-scoped ones are simply ignored. [tlotze, wosc]

2.0 (2013-09-19)

  • Remove need to explicitely create fixtures. [gotcha]

  • Add plone.testing.layered test suites support. [gotcha]

  • Made tests a bit more robust. [icemac]

1.0 (2013-08-28)

  • Initial release. [tlotze, icemac, gotcha]

Release files for zope.pytestlayer 9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zope.pytestlayer 9.2
File Size Uploaded
zope_pytestlayer-9.2.tar.gz 25.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zope.pytestlayer 9.2
File Interpreter ABI Platform
zope_pytestlayer-9.2-py3-none-any.whl Python 3 none any Details

Total release size: 63.1 kB

Release files / zope_pytestlayer-9.2.tar.gz

Download URL zope_pytestlayer-9.2.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bf9c468fe902581ff75bfe6f05b25fdcd6e1dc3f67e4f8f618e45e37a09e56dd
BLAKE2b-256 checksum
How to use checksums
c080065d451d46e4cbd5823e99a5c4d111e1353cc097be8dead4ec6e1cae20b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / zope_pytestlayer-9.2-py3-none-any.whl

Download URL zope_pytestlayer-9.2-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af733689512330b04cf75b20201e33c10f4702b38111f73337ae19729be3d156
BLAKE2b-256 checksum
How to use checksums
35467da37b3c87f7a4ce6f2f58a836d48fb77ad4f1739685515f136165925dbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

9.2 This release

2 release files

9.1

2 release files

9.0

2 release files

8.3

2 release files

8.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page