Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing your Plone codebase with pytest

Testing your Plone codebase with pytest

Plone 6 is out, and now you create your new CMS project with a cookiecutter template, install it with pip, format the code with black, and deploy it with Docker. But you probably still test it as you did 10 or 15 years ago. Learn how to use Pytest with Plone, and make TDD fun again. Over the last few years, the Plone community has been busy working on making Plone development more accessible to new developers with the adoption of well-known tools over homegrown solutions: The default installation of Plone is now based on pip, the recommended way to deploy is using containers, and if you want to bootstrap a new project, there is a cookiecutter template to do it. On the other hand, we still rely on the same patterns and snippets when testing the Python code of a Plone solution: Layers and test cases of Unittest, but there should be a better (more pythonic) way. Moving your tests from Unittest to Pytest is easy, and you gain access to all the features of the most comprehensive testing framework in the Python world. In this talk, we will present the reasoning for choosing Pytest over Unittest, but also show how your tests will be easier to write and maintain.

Érico Andrei

October 06, 2023
Tweet

More Decks by Érico Andrei

Other Decks in Technology

Transcript

  1. "Untested code is broken code" • First test: 2002-10-07 •

    unittest, unittest2 • Robot Framework, Selenium, Cypress Testing with Plone
  2. Keep Gil Forcada happy • 20 years of tests •

    Hundreds of packages • Plone 5.2, Plone 6.0 • Python 2.7, 3.7, 3.8, 3.9. 3.10, 3.11, 3.12 • GitHub Actions, Jenkins, pre- commit, mr.roboto • plone/meta Testing Plone
  3. A taste acquired when coding modern Python code • Simple

    & "Pythonic" • Dependency injection • Large ecosystem of plugins • Support for unittests Ich ❤ pytest
  4. • Built on top of gocept.pytestlayer • Provides Fixtures and

    Helpers • Already the default implementation on cookiecutter- plone-starter pytest-plone
  5. Growing adoption Distributions, new addons, old addons • plone.distribution •

    plonegovbr.portal_base • kitconcept.voltolighttheme • collective.ploneintranet • collective.mastodon • collective.bluesky • kitconcept.solr • contentrules.slack • collective.contact_behaviors • collective.person • collective.casestudy • pas.plugins.memberpropertytogroup