Before you can run the tests, you must install Kotti’s ‘testing’ extras. Inside your Kotti checkout directory, do:
bin/pip install -e .[testing]
To then run Kotti’s test suite, do:
Using Kotti’s test fixtures/funcargs in third party add-ons’ tests¶
To be able to use all of Kotti’s fixtures and funcargs in your own package’s tests, you only need to “include” them with a line like this in your
pytest_plugins = "kotti"
- class kotti.tests.TestStorage(**kwargs)
- kotti.tests.browser(db_session, request, setup_app)
returns an instance of zope.testbrowser. The kotti.testing.user pytest marker (or pytest.mark.user) can be used to pre-authenticate the browser with the given login name: @user(‘admin’).
returns a Pyramid Configurator object initialized with Kotti’s default (test) settings.
sets up a SQLAlchemy engine and returns a connection to the database. The connection string used for testing can be specified via the
KOTTI_TEST_DB_STRINGenvironment variable. The
custom_settingsfixture is needed to allow users to import their models easily instead of having to override the
- kotti.tests.content(connection, settings)
sets up some default content using Kotti’s testing populator.
This is a dummy fixture meant to be overridden in add on package’s
conftest.py. It can be used to inject arbitrary settings for third party test suites. The default settings dictionary will be updated with the dictionary returned by this fixture.
This is also a good place to import your add on’s
resourcesmodule to have the corresponding tables created during
- Return type
- kotti.tests.db_session(config, content, connection)
returns a db session object and sets up a db transaction savepoint, which will be rolled back after the test.
- kotti.tests.depot_tween(config, dummy_request)
Sets up the Depot tween and patches Depot’s
set_middlewareto suppress exceptions on subsequent calls. Yields the
- kotti.tests.dummy_request(config, request, monkeypatch)
returns a dummy request object after registering it as the currently active request. This is needed when pyramid.threadlocal.get_current_request is used.
- kotti.tests.filedepot(db_session, depot_tween)
Configures a dbsession integrated mock depot store for
Configures a mock depot store for
This filedepot is not integrated with dbsession. Can be used in simple, standalone unit tests.
- kotti.tests.no_filedepots(db_session, depot_tween)
A filedepot fixture to empty and then restore DepotManager configuration
Kotti itself is tested against Python versions 3.5 and 3.6 as well as SQLite, mySQL and PostgreSQL (in every possible combination of those) on every commit (and pull request) via the excellent GitHub / Travis CI hook.
If you want your add-on packages’ to be tested the same way with additional testing against multiple versions of Kotti (including the current master), you can add a
.travis.yml file to your repo that looks similar to this: