Skip to content

Commit 7a80a4e

Browse files
committed
test: refactor - move asyncio_run helper method to utils/__init__.py
1 parent 707a83a commit 7a80a4e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

tests/test_query.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import asyncio
2-
import inspect
3-
import sys
42
import time
5-
import traceback
63
import unittest
74
import os
85
import json
@@ -16,6 +13,7 @@
1613
from influxdb_client_3 import InfluxDBClient3
1714
from influxdb_client_3.query.query_api import QueryApiOptionsBuilder, QueryApi
1815
from influxdb_client_3.version import USER_AGENT
16+
from tests.util import asyncio_run
1917

2018
from tests.util.mocks import (
2119
ConstantData,
@@ -29,18 +27,6 @@
2927
)
3028

3129

32-
def asyncio_run(async_func):
33-
def wrapper(*args, **kwargs):
34-
try:
35-
return asyncio.run(async_func(*args, **kwargs))
36-
except Exception as e:
37-
print(traceback.format_exc(), file=sys.stderr)
38-
raise e
39-
40-
wrapper.__signature__ = inspect.signature(async_func)
41-
return wrapper
42-
43-
4430
def case_insensitive_header_lookup(headers, lkey):
4531
"""Lookup the value of a given key in the given headers.
4632
The lkey is case-insensitive.

tests/util/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
"""Package for tests/util module."""
2+
import asyncio
3+
import inspect
4+
import sys
5+
import traceback
6+
7+
8+
def asyncio_run(async_func):
9+
def wrapper(*args, **kwargs):
10+
try:
11+
return asyncio.run(async_func(*args, **kwargs))
12+
except Exception as e:
13+
print(traceback.format_exc(), file=sys.stderr)
14+
raise e
15+
16+
wrapper.__signature__ = inspect.signature(async_func)
17+
return wrapper

0 commit comments

Comments
 (0)