1
1
import os
2
2
from pathlib import Path
3
- from typing import Any , Generator , Optional
3
+ from typing import Any , Generator
4
4
5
+ import neo4j .exceptions
5
6
import pytest
6
7
from neo4j import Driver , GraphDatabase
7
8
23
24
24
25
DB = os .environ .get ("NEO4J_DB" , "neo4j" )
25
26
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 " )
27
28
AURA_DB_AUTH = ("neo4j" , "password" )
28
29
29
30
30
- @pytest .fixture (scope = "package" )
31
+ @pytest .fixture (scope = "package" , autouse = False )
31
32
def neo4j_driver () -> Generator [Driver , None , None ]:
32
33
driver = GraphDatabase .driver (URI , auth = AUTH )
33
34
@@ -36,7 +37,7 @@ def neo4j_driver() -> Generator[Driver, None, None]:
36
37
driver .close ()
37
38
38
39
39
- @pytest .fixture (scope = "package" )
40
+ @pytest .fixture (scope = "package" , autouse = False )
40
41
def runner (neo4j_driver : Driver ) -> Generator [Neo4jQueryRunner , None , None ]:
41
42
_runner = Neo4jQueryRunner .create (neo4j_driver )
42
43
_runner .set_database (DB )
@@ -46,7 +47,7 @@ def runner(neo4j_driver: Driver) -> Generator[Neo4jQueryRunner, None, None]:
46
47
_runner .close ()
47
48
48
49
49
- @pytest .fixture (scope = "package" )
50
+ @pytest .fixture (scope = "package" , autouse = False )
50
51
def gds () -> Generator [GraphDataScience , None , None ]:
51
52
_gds = GraphDataScience (URI , auth = AUTH )
52
53
_gds .set_database (DB )
@@ -56,7 +57,7 @@ def gds() -> Generator[GraphDataScience, None, None]:
56
57
_gds .close ()
57
58
58
59
59
- @pytest .fixture (scope = "package" )
60
+ @pytest .fixture (scope = "package" , autouse = False )
60
61
def gds_with_tls () -> Generator [GraphDataScience , None , None ]:
61
62
integration_test_dir = Path (__file__ ).resolve ().parent
62
63
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]:
78
79
_gds .close ()
79
80
80
81
81
- @pytest .fixture (scope = "package" )
82
+ @pytest .fixture (scope = "package" , autouse = False )
82
83
def gds_without_arrow () -> Generator [GraphDataScience , None , None ]:
83
84
_gds = GraphDataScience (URI , auth = AUTH , arrow = False )
84
85
_gds .set_database (DB )
@@ -89,19 +90,17 @@ def gds_without_arrow() -> Generator[GraphDataScience, None, None]:
89
90
90
91
91
92
@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 )
100
100
101
- yield _gds
101
+ yield _gds
102
102
103
- _gds .close ()
104
- return None
103
+ _gds .close ()
105
104
106
105
107
106
@pytest .fixture (autouse = True )
@@ -131,7 +130,10 @@ def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
131
130
if model .exists ():
132
131
model .drop (failIfMissing = True )
133
132
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 )
135
137
136
138
137
139
def pytest_collection_modifyitems (config : Any , items : Any ) -> None :
@@ -188,15 +190,12 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
188
190
if "cloud_architecture" in item .keywords :
189
191
item .add_marker (skip_cloud_architecture )
190
192
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
200
199
201
200
skip_incompatible_versions = pytest .mark .skip (reason = f"incompatible with GDS server version { server_version } " )
202
201
0 commit comments