Reference

Provides full reference to pytest-psqlgraph

Core Plugin

pytest_psqlgraph.plugin.inject_driver_fixture(fixture: pytest_psqlgraph.helpers.DatabaseFixture, request: _pytest.fixtures.SubRequest) None[source]

Resolves and setups psqlgraph driver fixtures based on psqlgraph_config entries

pytest_psqlgraph.plugin.inject_marker_data(mark: pytest_psqlgraph.models.PsqlgraphDataMark, item: _pytest.python.Function) None[source]

Resolves data for the custom psqlgraph data

Examples

@pytest.mark.psqlgraph_data(
  name="pg_data",
  driver_name="pg_driver",
  data_dir=here,
  resource="sample.yaml",
  post_processors=[append_mr],
)
def test_example(pg_driver: psqlgraph.PsqlGraphDriver, pg_data: List[psqlgraph.Node]) -> None:
  ...
pytest_psqlgraph.plugin.pytest_collection_finish(session: _pytest.main.Session) None[source]

A psqlgraph driver instance

Initializes the database tables and makes fixtures available .. rubric:: Example

code-block:

{"g": {
    "host": "localhost",
    "user": "test",
    "password": "test",
    "database": "test_db",
    "extra_bases": [],
    "models": model_module,
    "dictionary": dictionary instance
    }
}

models

class pytest_psqlgraph.models.DataModel(*args, **kwargs)[source]

Bases: Protocol

class pytest_psqlgraph.models.DatabaseDriverConfig(host: str, user: str, password: str, database: str, model: pytest_psqlgraph.models.DataModel, dictionary: pytest_psqlgraph.models.Dictionary, package_namespace: Optional[str] = None, orm_base: Optional[sqlalchemy.ext.declarative.api.DeclarativeMeta] = None, extra_bases: Optional[Iterable[sqlalchemy.ext.declarative.api.DeclarativeMeta]] = None, globals: Optional[Dict[str, Any]] = None)[source]

Bases: object

psqlgraph database configuration data

host

postgres database hostname with port (if non default)

Type

str

user

postgres database username

Type

str

password

postgres database user password

Type

str

database

postgres database name to connect to

Type

str

package_namespace

optional parameter used to demarcate driver model classes

Type

Optional[str]

model

The python module containing all the models associated with this database

Type

pytest_psqlgraph.models.DataModel

dictionary

The instance containing the dictionary definitions

Type

pytest_psqlgraph.models.Dictionary

orm_base

Optional sqlalchemy declarative base used by all models, this defaults to psqlgraph ORMBase

Type

Optional[sqlalchemy.ext.declarative.api.DeclarativeMeta]

extra_bases

Iterable of bases that needs to be created/destroyed as part of the driver

Type

Optional[Iterable[sqlalchemy.ext.declarative.api.DeclarativeMeta]]

globals

optional default property keys and values used for all nodes created

Type

Optional[Dict[str, Any]]

class pytest_psqlgraph.models.Dictionary(*args, **kwargs)[source]

Bases: Protocol

A dictionary template

schema

node name and schema pairs

Type

Dict[str, psqlgml.types.DictionarySchemaDict]

class pytest_psqlgraph.models.MarkExtension(g: psqlgraph.psql.PsqlGraphDriver)[source]

Bases: object

An extension for psqlgraph data marker

post(nodes: Iterable[psqlgraph.node.Node]) None[source]

Same as pre, but executes after data has been persisted

Parameters

nodes – all nodes generated and persisted

pre(nodes: Iterable[psqlgraph.node.Node]) None[source]

Executes just before the generated nodes are written to the database

Parameters

nodes – list of nodes pull from the test data that will be written to the database

run(node: psqlgraph.node.Node) None[source]

Executes within the same transaction as the one that will write the current node

Parameters

node – the current node just before it is added to the database

class pytest_psqlgraph.models.PsqlgraphDataMark(*args, **kwargs)[source]

Bases: dict

helpers

Helper functions

pytest_psqlgraph.helpers.drop_tables(driver: pytest_psqlgraph.models.DatabaseDriver) None[source]

Drops all tables in the listed orm_bases

pytest_psqlgraph.helpers.truncate_tables(pg_driver: psqlgraph.psql.PsqlGraphDriver) None[source]

Truncates all entries in the database

Parameters

pg_driver – active driver