Skip to main content

pytest-plone

PyPI PyPI - Python Version PyPI - Wheel PyPI - License PyPI - Status

PyPI - Plone Versions

Code analysis checks Tests Code Style

GitHub contributors GitHub Repo stars

pytest-plone is a pytest plugin providing fixtures and helpers to test Plone add-ons.

This package is built on top of gocept.pytestlayer.

Reasoning

Despite the fact Plone, and Zope, have their codebases tested with unittest, over the years pytest became the most popular choice for testing in Python.

pytest is more flexible and easier to use than unittest and has a rich ecosystem of plugins that you can use to extend its functionality.

Warning

THIS PACKAGE IS NOT CONSIDERED TO BE STABLE AND FIXTURES COULD CHANGE BEFORE A FINAL RELEASE

Usage

In your top-level conftest.py import your testing layers, and also import fixtures_factory -- which will accept a iterator of tuples containing the testing layer and a prefix to be used to generate the needed pytest fixtures.

from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING
from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_INTEGRATION_TESTING
from pytest_plone import fixtures_factory


globals().update(
    fixtures_factory(
        (
            (PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING, "functional"),
            (PRODUCTS_CMFPLONE_INTEGRATION_TESTING, "integration"),
        )
    )
)

In the code above, the following pytest fixtures will be available to your tests:

Fixture Scope
functional_session Session
functional_class Class
functional Function
integration_session Session
integration_class Class
integration Function

Fixtures

portal

Description Portal object
Required Fixture integration
Scope Function
def test_portal_title(portal):
    """Test portal title."""
    assert portal.title == "Plone Site"

http_request

Description HTTP Request
Required Fixture integration
Scope Function
from plone import api


def test_myproduct_controlpanel_view(portal, http_request):
    """Test myproduct_controlpanel browser view is available."""
    view = api.content.get_view(
        "myproduct-controlpanel", portal, http_request
    )
    assert view is not None

installer

Description Installer browser view. Used to install/uninstall/check for an add-on.
Required Fixture integration
Scope Function
import pytest


PACKAGE_NAME = "myproduct"


@pytest.fixture
def uninstall(installer):
    """Fixture to uninstall a package."""
    installer.uninstall_product(PACKAGE_NAME)


def test_product_installed(installer):
    """Test if myproduct is installed."""
    assert installer.is_product_installed(PACKAGE_NAME) is True

@pytest.mark.parametrize(
    "package",
    [
        "collective.casestudy",
        "pytest-plone",
    ]
)
def test_dependency_installed(installer, package):
    """Test if dependency is installed."""
    assert installer.is_product_installed(package) is True

browser_layers

Description List of available browser layers. Used to test if a specific browser layer is registered.
Required Fixture integration
Scope Function
def test_browserlayer(browser_layers):
    """Test that IMyProductLayer is registered."""
    from myproduct.interfaces import IMyProductLayer


    assert IMyProductLayer in browser_layers

controlpanel_actions

Description List of control panel actions ids. Used to test if a specific control panel is installed or not.
Required Fixture integration
Scope Function
def test_configlet_install(controlpanel_actions):
    """Test if control panel is installed."""
    assert "myproductcontrolpanel" in controlpanel_actions

Plugin Development

You need a working python environment (system, virtualenv, pyenv, etc) version 3.8 or superior.

Then install the dependencies and a development instance using:

make build

To run tests for this package:

make test

By default we use the latest Plone version in the 6.x series.

License

The project is licensed under the GPLv2.

Changelog

0.1.0 (2023-01-04)

  • Fixtures portal, http_request, installer, browser_layers, controlpanel_actions [ericof]

  • Initial release [ericof]

Metadata

Release files for pytest-plone 0.1.0

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

Source distribution (sdist)

Source distribution for pytest-plone 0.1.0
File Size Uploaded Provenance Actions
pytest-plone-0.1.0.tar.gz 14.3 kB Without provenance Details for pytest-plone-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-plone 0.1.0
File Interpreter ABI Platform Actions
pytest_plone-0.1.0-py3-none-any.whl Python 3 none any Details for pytest_plone-0.1.0-py3-none-any.whl

Total release size: 25.8 kB

Release files / pytest-plone-0.1.0.tar.gz

Download URL pytest-plone-0.1.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f3eab1c436970cfebcd7fd24c6bcf78f6a4abb40ca41ae77a5eda97ccd3fb8fa
BLAKE2b-256 checksum
How to use checksums
c50613511857f066e80d6585e7fa66a9cb3c8c1b281d2719ebb72a141fc04f2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Release files / pytest_plone-0.1.0-py3-none-any.whl

Download URL pytest_plone-0.1.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
998f5d3744c8fabfc9abba903684852713cd7f4e25159ed864826b560d4636ef
BLAKE2b-256 checksum
How to use checksums
2447d03b3d8a4a6eb7383e718762799ffbe345617dcfcc353f72a5fd8fe3c0a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Security for pytest-plone 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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