Skip to content

Commit 8a6d22e

Browse files
author
Alejo Sanchez
committed
test.py topology: session scope for common fixtures
Change default pytest-asyncio event_loop fixture scope to session to allow async fixtures with scope larger than function. See pytest-dev/pytest-asyncio#68 Change temporarily table1 fixture to session scope. Signed-off-by: Alejo Sanchez <[email protected]>
1 parent d78263e commit 8a6d22e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

test/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from cassandra.cluster import ExecutionProfile, EXEC_PROFILE_DEFAULT # type: ignore
1616
from cassandra.policies import RoundRobinPolicy # type: ignore
1717
from test.pylib.util import unique_name # type: ignore
18+
import asyncio
1819
import pytest
1920
import ssl
2021

@@ -30,6 +31,17 @@ def pytest_addoption(parser):
3031
parser.addoption('--ssl', action='store_true',
3132
help='Connect to CQL via an encrypted TLSv1.2 connection')
3233

34+
35+
# Change default pytest-asyncio event_loop fixture scope to session to
36+
# allow async fixtures with scope larger than function.
37+
# See https://github.com/pytest-dev/pytest-asyncio/issues/68
38+
@pytest.fixture(scope="session")
39+
def event_loop(request):
40+
loop = asyncio.get_event_loop_policy().new_event_loop()
41+
yield loop
42+
loop.close()
43+
44+
3345
# "cql" fixture: set up client object for communicating with the CQL API.
3446
# The host/port combination of the server are determined by the --host and
3547
# --port options, and defaults to localhost and 9042, respectively.

test/topology/test_null.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010

11-
@pytest.fixture(scope="module")
11+
@pytest.fixture(scope="session")
1212
def table1(cql, test_keyspace):
1313
table = test_keyspace + "." + unique_name()
1414
cql.execute(f"CREATE TABLE {table} (p text, c text, v text, primary key (p, c))")

0 commit comments

Comments
 (0)