Skip to content

Commit b7ee29f

Browse files
Fix up unit tests (#999)
* Fix deprecated event loop handling in async tests * Fix tests: stdout/stderr get implicitly mocked Co-authored-by: grant lodge <[email protected]>
1 parent 756ceb6 commit b7ee29f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def neo4j_session(neo4j_driver):
169169
# async support for pytest-benchmark
170170
# https://github.com/ionelmc/pytest-benchmark/issues/66
171171
@pytest_asyncio.fixture
172-
async def aio_benchmark(benchmark, event_loop):
172+
def aio_benchmark(benchmark, event_loop):
173173
def _wrapper(func, *args, **kwargs):
174174
if asyncio.iscoroutinefunction(func):
175175
@benchmark

tests/unit/common/test_debug.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,35 @@ def test_watcher_level_multiple_watchers(
207207

208208
custom_log_out = io.StringIO()
209209

210+
210211
@pytest.mark.parametrize(
211212
("default_out", "out", "expected_out"),
212213
(
213-
(None, None, sys.stderr),
214-
(sys.stdout, None, sys.stdout),
215-
(sys.stdout, sys.stderr, sys.stderr),
216-
(sys.stderr, sys.stdout, sys.stdout),
214+
(None, None, "stderr"),
215+
("stdout", None, "stdout"),
216+
("stdout", "stderr", "stderr"),
217+
("stderr", "stdout", "stdout"),
217218
(custom_log_out, None, custom_log_out),
218219
(None, custom_log_out, custom_log_out),
219220
)
220221
)
221222
def test_watcher_out(
222223
logger_mocker, default_out, out, expected_out
223224
) -> None:
225+
def normalize_stream(stream):
226+
# For some reason (probably a change in pytest), sys.stdout and
227+
# sys.stderr are replaced with a custom io.TextIOWrapper.
228+
# Therefore, we grab them dynamically within the test.
229+
if isinstance(stream, str):
230+
if stream == "stdout":
231+
return sys.stdout
232+
elif stream == "stderr":
233+
return sys.stderr
234+
return stream
235+
236+
default_out = normalize_stream(default_out)
237+
out = normalize_stream(out)
238+
expected_out = normalize_stream(expected_out)
224239
logger_name = "neo4j"
225240
logger = logger_mocker(logger_name)[0]
226241
kwargs = {}

0 commit comments

Comments
 (0)