Features

Markers

pytest-psqlgraph registers the following markers. See the pytest documentation on pytest markers and for notes on using markers.

pytest.mark.psqlgraph_data - load test data

pytest.mark.psqlgraph_data(name: str, driver_name: str, data_dir: str, resource: str, unique_key: str, mock_all_props: bool, post_processors)

The mark used to pass options to your application config.

Parameters
  • name (str) – The name of the variable injected into the test function that will hold the result of fixture.

  • driver_name (str) – matching psqlgraph driver name

  • data_dir (str) – A directory that holds all the data files used in test data generation

  • resource (str) – name of the resource to load relative to the data_dir

  • unique_key (str) – name of the property used for linking multiple nodes together. Defaults to node_id

  • unique_key – Optional flag that specify how unspecified properties are generated. If True all node properties will be autogenerated

  • post_processor – a collection of functions that will be executed once the nodes are generated

Return type

list[psqgraph.Node]

Example usage:

# define a sample post action
def append_mr(node: psqlgraph.Node) -> None:
     """Appends Mr. to father's name"""
     node.name = "Mr. {}".format(node.name)

@pytest.mark.psqlgraph_data(
     name="pg_data",
     driver_name="pg_driver",
     data_dir=here,
     resource="sample.yaml",
     unique_key="node_id",
     mock_all_props=True,
     post_processors=[append_mr],
 )
 def test_pgdata_with_yaml(
     pg_driver: psqlgraph.PsqlGraphDriver, pg_data: List[psqlgraph.Node]
 ):
     """Tests use of pgdata to load initial from yaml/json"""

     assert len(pg_data) == 3
     with pg_driver.session_scope():
         node = pg_driver.nodes().get("father-1")
         assert node.name == "Mr. Samson O."