Integration of zope.testrunner-style test layers into pytest framework
The gocept.pytestlayer distribution
Integration of zope.testrunner-style test layers into the pytest framework
This package is compatible with Python versions 3.7 - 3.10 including PyPy3.
Make sure your test files follow the conventions of pytest’s test discovery
In particular, a file named tests.py will not be recognised.
Add a buildout section to create the pytest runner:
[buildout] parts += pytest [pytest] recipe = zc.recipe.egg eggs = gocept.pytestlayer pytest <YOUR PACKAGE HERE>
gocept.pytestlayer registers itself as a pytest plugin. This way, nothing more is needed to run an existing Zope or Plone test suite.
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 gocept.pytestlayer.fixture globals().update(gocept.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.
- PyPI page:
- Source code:
- Current change log:
Change log for gocept.pytestlayer
Ensure compatibility with pytest >= 7.1.3. .layered.LayeredTestCaseInstance now has to inherit from _pytest.unittest.UnitTestCase.
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.
Backwards imcompatible changes
Drop support for Python 2.7 and 3.5 and pytest < 5.0. (#8)
Support pytest >= 6.0. (#8)
Ensure compatibility with pytest > 5.4.2. We need a _explicit_tearDown on our LayeredTestCaseFunction now.
Ensure compatibility with pytest > 5.4. We need a _needs_explicit_tearDown on our LayeredTestCaseFunction now.
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.
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)
Make installation process compatible with setuptools >= 30.0.
Fix tests to pass if pytest >= 3.0 is used for testing.
Support Python 3.4, 3.5 and PyPy.
Use tox as testrunner.
Claim compatibility with py.test 2.9.x.
Drop Python 2.6 support.
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]
Remove need to explicitely create fixtures. [gotcha]
Add plone.testing.layered test suites support. [gotcha]
Made tests a bit more robust. [icemac]
Initial release. [tlotze, icemac, gotcha]
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for gocept.pytestlayer-8.1-py3-none-any.whl