Skip to content

Commit 21b5625

Browse files
committed
Make fixture resolution order determinist on Python < 3.6
1 parent f6b3739 commit 21b5625

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pytest_trio/plugin.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
"""pytest-trio implementation."""
2+
import sys
23
from traceback import format_exception
34
from inspect import iscoroutinefunction, isgeneratorfunction
4-
try:
5-
from inspect import isasyncgenfunction
6-
except ImportError:
7-
# `inspect.isasyncgenfunction` not available with Python<3.6
8-
def isasyncgenfunction(x):
9-
return False
10-
11-
125
import pytest
136
import trio
147
from trio._util import acontextmanager
158
from trio.testing import MockClock, trio_test
169
from async_generator import async_generator, yield_
1710

11+
if sys.version_info >= (3, 6):
12+
from inspect import isasyncgenfunction
13+
ORDERED_DICTS = True
14+
else:
15+
# `inspect.isasyncgenfunction` not available with Python<3.6
16+
def isasyncgenfunction(x):
17+
return False
18+
19+
# Ordered dict (and **kwargs) not available with Python<3.6
20+
ORDERED_DICTS = False
21+
1822

1923
def pytest_configure(config):
2024
"""Inject documentation."""
@@ -69,6 +73,9 @@ async def _setup_async_fixtures_in(deps):
6973
need_resolved_deps_stack = [
7074
(k, v) for k, v in deps.items() if isinstance(v, BaseAsyncFixture)
7175
]
76+
if not ORDERED_DICTS:
77+
# Make the fixture resolution order determinist
78+
need_resolved_deps_stack = sorted(need_resolved_deps_stack)
7279

7380
if not need_resolved_deps_stack:
7481
await yield_(deps)

0 commit comments

Comments
 (0)