Skip to content

Commit f2da645

Browse files
committed
Rework test_async_fixture_concurrent_teardown to avoid time-dependence
1 parent 14b16ca commit f2da645

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

testing/test_basic.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -210,53 +210,34 @@ def test_succeed(foo):
210210
@skip_if_no_async_generators()
211211
def test_async_fixture_concurrent_teardown(testdir, cmd_opts):
212212
test_file = """
213-
import time
214-
215213
from twisted.internet import reactor, defer
216214
import pytest
217215
import pytest_twisted
218216
219-
def sleep(seconds):
220-
d = defer.Deferred()
221-
222-
reactor.callLater(seconds, d.callback, None)
223-
224-
return d
225-
226-
short_times = []
227-
long_times = []
228217
229-
short_time = 0.100
230-
long_time = 1
218+
here = defer.Deferred()
219+
there = defer.Deferred()
231220
232221
@pytest.fixture
233-
async def short():
222+
async def this():
234223
yield 42
235224
236-
short_times.append(time.time())
237-
await sleep(short_time)
238-
short_times.append(time.time())
225+
there.callback(None)
226+
await here
239227
240228
@pytest.fixture
241-
async def long():
229+
async def that():
242230
yield 37
243231
244-
long_times.append(time.time())
245-
await sleep(short_time)
246-
long_times.append(time.time())
232+
here.callback(None)
233+
await there
247234
248-
assert len(short_times) == 2
249-
250-
# long should start before short finishes
251-
assert long_times[0] < short_times[1]
252-
# short should finish before long finishes
253-
assert short_times[1] < long_times[1]
254-
255-
@pytest_twisted.inlineCallbacks
256-
def test_succeed(short, long):
257-
yield sleep(0)
235+
def test_succeed(this, that):
236+
pass
258237
"""
259238
testdir.makepyfile(test_file)
239+
# TODO: add a timeout, failure just hangs indefinitely for now
240+
# https://github.com/pytest-dev/pytest/issues/4073
260241
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
261242
assert_outcomes(rr, {"passed": 1})
262243

0 commit comments

Comments
 (0)