swh.core.db.pytest_plugin module

class swh.core.db.pytest_plugin.SWHDatabaseJanitor(user: str, host: str, port: str, db_name: str, version: Union[str, float, pkg_resources.extern.packaging.version.Version], dump_files: Optional[str] = None, no_truncate_tables: Set[str] = {})[source]

Bases: pytest_postgresql.janitor.DatabaseJanitor

SWH database janitor implementation with a a different setup/teardown policy than than the stock one. Instead of dropping, creating and initializing the database for each test, it creates and initializes the db once, then truncates the tables (and sequences) in between tests.

This is needed to have acceptable test performances.


Truncate tables (all but self.no_truncate_tables set) and sequences


Initialize db. Create the db if it does not exist. Reset it if it exists.


The original DatabaseJanitor implementation prevents new connections from happening, destroys current opened connections and finally drops the database.

We actually do not want to drop the db so we instead do nothing and resets (truncate most tables and sequences) the db instead, in order to have some acceptable performance.

swh.core.db.pytest_plugin.postgresql_fact(process_fixture_name: str, db_name: Optional[str] = None, dump_files: str = '', no_truncate_tables: Set[str] = {'dbversion'})[source]