11import os
22from pathlib import Path
3- from typing import Any , Generator , Optional
3+ from typing import Any , Generator
44
5+ import neo4j .exceptions
56import pytest
67from neo4j import Driver , GraphDatabase
78
2324
2425DB = os .environ .get ("NEO4J_DB" , "neo4j" )
2526
26- AURA_DB_URI = os .environ .get ("NEO4J_AURA_DB_URI " , "bolt://localhost:7689 " )
27+ AURA_DB_URI = os .environ .get ("AURA_DB_URI " , "bolt://localhost:7687 " )
2728AURA_DB_AUTH = ("neo4j" , "password" )
2829
2930
30- @pytest .fixture (scope = "package" )
31+ @pytest .fixture (scope = "package" , autouse = False )
3132def neo4j_driver () -> Generator [Driver , None , None ]:
3233 driver = GraphDatabase .driver (URI , auth = AUTH )
3334
@@ -36,7 +37,7 @@ def neo4j_driver() -> Generator[Driver, None, None]:
3637 driver .close ()
3738
3839
39- @pytest .fixture (scope = "package" )
40+ @pytest .fixture (scope = "package" , autouse = False )
4041def runner (neo4j_driver : Driver ) -> Generator [Neo4jQueryRunner , None , None ]:
4142 _runner = Neo4jQueryRunner .create (neo4j_driver )
4243 _runner .set_database (DB )
@@ -46,7 +47,7 @@ def runner(neo4j_driver: Driver) -> Generator[Neo4jQueryRunner, None, None]:
4647 _runner .close ()
4748
4849
49- @pytest .fixture (scope = "package" )
50+ @pytest .fixture (scope = "package" , autouse = False )
5051def gds () -> Generator [GraphDataScience , None , None ]:
5152 _gds = GraphDataScience (URI , auth = AUTH )
5253 _gds .set_database (DB )
@@ -56,7 +57,7 @@ def gds() -> Generator[GraphDataScience, None, None]:
5657 _gds .close ()
5758
5859
59- @pytest .fixture (scope = "package" )
60+ @pytest .fixture (scope = "package" , autouse = False )
6061def gds_with_tls () -> Generator [GraphDataScience , None , None ]:
6162 integration_test_dir = Path (__file__ ).resolve ().parent
6263 cert = os .path .join (integration_test_dir , "resources" , "arrow-flight-gds-test.crt" )
@@ -78,7 +79,7 @@ def gds_with_tls() -> Generator[GraphDataScience, None, None]:
7879 _gds .close ()
7980
8081
81- @pytest .fixture (scope = "package" )
82+ @pytest .fixture (scope = "package" , autouse = False )
8283def gds_without_arrow () -> Generator [GraphDataScience , None , None ]:
8384 _gds = GraphDataScience (URI , auth = AUTH , arrow = False )
8485 _gds .set_database (DB )
@@ -89,19 +90,17 @@ def gds_without_arrow() -> Generator[GraphDataScience, None, None]:
8990
9091
9192@pytest .fixture (scope = "package" , autouse = False )
92- def gds_with_cloud_setup (request : pytest .FixtureRequest ) -> Optional [Generator [AuraGraphDataScience , None , None ]]:
93- if "cloud_architecture" not in request .keywords :
94- _gds = AuraGraphDataScience .create (
95- gds_session_connection_info = DbmsConnectionInfo (URI , AUTH [0 ], AUTH [1 ]),
96- db_connection_info = DbmsConnectionInfo (AURA_DB_URI , AURA_DB_AUTH [0 ], AURA_DB_AUTH [1 ]),
97- delete_fn = lambda : True ,
98- )
99- _gds .set_database (DB )
93+ def gds_with_cloud_setup (request : pytest .FixtureRequest ) -> Generator [AuraGraphDataScience , None , None ]:
94+ _gds = AuraGraphDataScience .create (
95+ gds_session_connection_info = DbmsConnectionInfo (URI , AUTH [0 ], AUTH [1 ]),
96+ db_connection_info = DbmsConnectionInfo (AURA_DB_URI , AURA_DB_AUTH [0 ], AURA_DB_AUTH [1 ]),
97+ delete_fn = lambda : True ,
98+ )
99+ _gds .set_database (DB )
100100
101- yield _gds
101+ yield _gds
102102
103- _gds .close ()
104- return None
103+ _gds .close ()
105104
106105
107106@pytest .fixture (autouse = True )
@@ -131,7 +130,10 @@ def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
131130 if model .exists ():
132131 model .drop (failIfMissing = True )
133132
134- gds .run_cypher ("MATCH (n) DETACH DELETE (n)" )
133+ try :
134+ gds .run_cypher ("MATCH (n) DETACH DELETE (n)" )
135+ except neo4j .exceptions .ClientError as e :
136+ print (e )
135137
136138
137139def pytest_collection_modifyitems (config : Any , items : Any ) -> None :
@@ -188,15 +190,12 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
188190 if "cloud_architecture" in item .keywords :
189191 item .add_marker (skip_cloud_architecture )
190192
191- gds = GraphDataScience (URI , auth = AUTH )
192-
193- try :
194- server_version = gds ._server_version
195- except Exception as e :
196- print ("Could not derive GDS library server version" )
197- raise e
198- finally :
199- gds .close ()
193+ with GraphDataScience (URI , auth = AUTH ) as gds :
194+ try :
195+ server_version = gds ._server_version
196+ except Exception as e :
197+ print ("Could not derive GDS library server version" )
198+ raise e
200199
201200 skip_incompatible_versions = pytest .mark .skip (reason = f"incompatible with GDS server version { server_version } " )
202201
0 commit comments