Skip to content

Commit 2b89fc1

Browse files
committed
Use closest run-specifying marker, else config
1 parent 68860e0 commit 2b89fc1

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

pytest_trio/_tests/test_trio_mode.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,46 @@ async def test():
138138
f"*ValueError: {run_name!r} not valid for 'trio_run' config. Must be one of: *"
139139
]
140140
)
141+
142+
143+
def test_closest_explicit_run_wins(testdir):
144+
testdir.makefile(
145+
".ini", pytest=f"[pytest]\ntrio_mode = true\ntrio_run = trio\n"
146+
)
147+
testdir.makepyfile(qtrio=qtrio_text)
148+
149+
test_text = """
150+
import pytest
151+
import pytest_trio
152+
import qtrio
153+
154+
@pytest.mark.trio(run='should be ignored')
155+
@pytest.mark.trio(run=qtrio.run)
156+
async def test():
157+
assert qtrio.fake_used
158+
"""
159+
testdir.makepyfile(test_text)
160+
161+
result = testdir.runpytest()
162+
result.assert_outcomes(passed=1)
163+
164+
165+
def test_ini_run_wins_with_blank_marker(testdir):
166+
testdir.makefile(
167+
".ini", pytest=f"[pytest]\ntrio_mode = true\ntrio_run = qtrio\n"
168+
)
169+
testdir.makepyfile(qtrio=qtrio_text)
170+
171+
test_text = """
172+
import pytest
173+
import pytest_trio
174+
import qtrio
175+
176+
@pytest.mark.trio
177+
async def test():
178+
assert qtrio.fake_used
179+
"""
180+
testdir.makepyfile(test_text)
181+
182+
result = testdir.runpytest()
183+
result.assert_outcomes(passed=1)

pytest_trio/plugin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,15 @@ def _trio_test_runner_factory(item, testfunc=None):
353353
else:
354354
testfunc = item.obj
355355

356-
config_run = choose_run(config=item.config)
357-
marker = item.get_closest_marker("trio")
358-
run = marker.kwargs.get('run', config_run)
356+
for marker in item.iter_markers("trio"):
357+
maybe_run = marker.kwargs.get('run')
358+
if maybe_run is not None:
359+
run = maybe_run
360+
break
361+
else:
362+
# no marker found that explicitly specifiers the runner so use config
363+
run = choose_run(config=item.config)
364+
359365

360366
if getattr(testfunc, '_trio_test_runner_wrapped', False):
361367
# We have already wrapped this, perhaps because we combined Hypothesis

0 commit comments

Comments
 (0)