Testing an addon in a pip instance

Hi

I have a plone 6 instance created with cookiecutter, mxdev and pip and I've added an addon. I can start the instance with runwsgi but can someone tell me how to run my addon's tests.

Thanks
Mike

When zope.testrunner is installed, it comes with a console script for running the tests. You can use it like this:

zope-testrunner --test-path path/to/addon

Thanks @davisagli

FYI, we are working on a Makefile with a snippet include system (mxmake) as glue around all this. I'll come back if this is ready.

What is the recommended way to create addon for this setup?
In buildout based installations it would go to src/something.content and then references added to eggs location.

Pure pip based you install pip -e src/something.content (or add a line -e src/ something.content to your requirements.txt and install it) and include the ZCML in the zope configuration.

Or if the package is in git use mxdev.

Instead of manual editing the zope configuration you can use the cookiecutter as mentioned above to generate everything ready to use.

My steps to create an addon with installation of Plone 6.

mkdir testfolder
cd testfolder
python -m venv ./venv
source venv/bin/activate
touch requirements.txt
touch constraints.txt
touch instance.yaml

edit the requirements.txt

vim requirements.txt
-c constraints.txt
wheel
# mr.bob checkout only needed if python 3.10
git+https://github.com/collective/mr.bob.git@master
plonecli
cookiecutter
mxdev
zope.testrunner
Plone

edit the constraints.txt

vim constraints.txt
# add the following line to constraints.txt
-c https://dist.plone.org/release/6.0.0b2/constraints.txt

run pip install

pip install -r requirements.txt

create an addon in ./src

plonecli create addon src/my.addon
# some questions to answer

edit the requirements.txt and append the local package my.addon

vim requirements.txt
# append this tow lines to requirements.txt
-e src/my.addon
-e src/my.addon[test]

rerun pip install

pip install -r requirements.txt

edit the config for zope config creation

vim instance.yaml
# instance.yaml
default_context:
  initial_user_name: "admin"
  initial_user_password: "admin"

  load_zcml:
    package_includes: ["my.addon"]

  db_storage: direct

create zope a custom config and start the instance

cookiecutter -f --no-input --config-file instance.yaml https://github.com/plone/cookiecutter-zope-instance
runwsgi -v instance/etc/zope.ini

Now my Question, what is the right way to start the tests in the package my.addon?
I started zope-testrunner with the following command:

> zope-testrunner -pvc --test-path=src/my.addon/src/my/addon/

But it ends with an error:

Test-module import failures:

Module: tests.test_robot

ModuleNotFoundError: No module named 'tests'

Module: tests.test_setup

ModuleNotFoundError: No module named 'tests'

Running tests at level 1

Test-modules with import problems:
  tests.test_robot
  tests.test_setup
Total: 0 tests, 0 failures, 2 errors, 0 skipped in 0.000 seconds.

Update, Problem solved

@ksuess Thanks for the hint. The tests are running now.

> zope-testrunner -pvc --test-path=src/my.addon/src/
1 Like

zope-testrunner -pvc --test-path=src/my.addon/src/

The path to your source tree is src/my.addon/src/

1 Like