swh.core.db.pytest_plugin module

class swh.core.db.pytest_plugin.SWHDatabaseJanitor(user: str, host: str, port: str, dbname: str, version: Union[str, float], dump_files: Union[None, str, List[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.

Initialize janitor.

Parameters
  • user – postgresql username

  • host – postgresql host

  • port – postgresql port

  • dbname – database name

  • version – postgresql version number

  • password – optional postgresql password

  • isolation_level – optional postgresql isolation level defaults to ISOLATION_LEVEL_AUTOCOMMIT

  • connection_timeout – how long to retry connection before raising a TimeoutError

db_setup()[source]
db_reset()[source]

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

init()[source]

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

drop()[source]

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, dbname: Optional[str] = None, dump_files: Union[str, List[str]] = '', no_truncate_tables: Set[str] = {'dbversion'})[source]