Skip to content

Commit a6c8765

Browse files
authored
Fix deprecation warnings in integration tests (#762)
1 parent a41f827 commit a6c8765

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

tests/integration/async_/test_custom_ssl_context.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
import pytest
2121

22-
from neo4j import AsyncGraphDatabase
22+
import neo4j
23+
from neo4j._async_compat.util import AsyncUtil
2324

2425
from ..._async_compat import mark_async_test
26+
from ...conftest import get_async_driver_no_warning
2527

2628

2729
@mark_async_test
@@ -39,9 +41,14 @@ def wrap_fail(*_, **__):
3941
fake_ssl_context.wrap_socket.side_effect = wrap_fail
4042
fake_ssl_context.wrap_bio.side_effect = wrap_fail
4143

42-
driver = AsyncGraphDatabase.driver(
43-
uri, auth=auth, ssl_context=fake_ssl_context
44-
)
44+
if AsyncUtil.is_async_code:
45+
driver = get_async_driver_no_warning(
46+
uri, auth=auth, ssl_context=fake_ssl_context
47+
)
48+
else:
49+
driver = neo4j.GraphDatabase.driver(
50+
uri, auth=auth, ssl_context=fake_ssl_context
51+
)
4552
async with driver:
4653
async with driver.session() as session:
4754
with pytest.raises(NoNeedToGoFurtherException):

tests/integration/examples/test_custom_resolver_example.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ def resolver(address):
5050

5151

5252
def add_person(name):
53-
driver = create_driver("neo4j://x.example.com", user="neo4j", password="password")
54-
session = driver.session(default_access_mode=WRITE_ACCESS)
55-
session.run("CREATE (a:Person {name: $name})", {"name", name})
56-
session.close()
57-
driver.close()
53+
driver = create_driver("neo4j://x.example.com",
54+
user="neo4j", password="password")
55+
try:
56+
with driver.session(default_access_mode=WRITE_ACCESS) as session:
57+
session.run("CREATE (a:Person {name: $name})", {"name", name})
58+
finally:
59+
driver.close()
5860
# end::custom-resolver[]
5961

6062

tests/integration/examples/test_pass_bookmarks_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def main(self):
9696

9797

9898
def test(uri, auth):
99+
eg = BookmarksExample(uri, auth)
99100
try:
100-
eg = BookmarksExample(uri, auth)
101101
with eg.driver.session() as session:
102102
session.run("MATCH (_) DETACH DELETE _")
103103
eg.main()
@@ -106,3 +106,5 @@ def test(uri, auth):
106106
except ServiceUnavailable as error:
107107
if isinstance(error.__cause__, BoltHandshakeError):
108108
pytest.skip(error.args[0])
109+
finally:
110+
eg.close()

tests/integration/sync/test_custom_ssl_context.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
import pytest
2121

22-
from neo4j import GraphDatabase
22+
import neo4j
23+
from neo4j._async_compat.util import Util
2324

2425
from ..._async_compat import mark_sync_test
26+
from ...conftest import get_async_driver_no_warning
2527

2628

2729
@mark_sync_test
@@ -39,9 +41,14 @@ def wrap_fail(*_, **__):
3941
fake_ssl_context.wrap_socket.side_effect = wrap_fail
4042
fake_ssl_context.wrap_bio.side_effect = wrap_fail
4143

42-
driver = GraphDatabase.driver(
43-
uri, auth=auth, ssl_context=fake_ssl_context
44-
)
44+
if Util.is_async_code:
45+
driver = get_async_driver_no_warning(
46+
uri, auth=auth, ssl_context=fake_ssl_context
47+
)
48+
else:
49+
driver = neo4j.GraphDatabase.driver(
50+
uri, auth=auth, ssl_context=fake_ssl_context
51+
)
4552
with driver:
4653
with driver.session() as session:
4754
with pytest.raises(NoNeedToGoFurtherException):

0 commit comments

Comments
 (0)