Skip to content

Commit 44cd8a3

Browse files
nicoddemusbluetech
andauthored
Demonstrate that plain unittest does not support async tests (#7607)
Co-authored-by: Ran Benita <[email protected]>
1 parent 2bd0d97 commit 44cd8a3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import unittest
2+
3+
4+
class Test(unittest.TestCase):
5+
async def test_foo(self):
6+
assert False

testing/test_unittest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,3 +1241,18 @@ def test_asynctest_support(testdir):
12411241
testdir.copy_example("unittest/test_unittest_asynctest.py")
12421242
reprec = testdir.inline_run()
12431243
reprec.assertoutcome(failed=1, passed=2)
1244+
1245+
1246+
def test_plain_unittest_does_not_support_async(testdir):
1247+
"""Async functions in plain unittest.TestCase subclasses are not supported without plugins.
1248+
1249+
This test exists here to avoid introducing this support by accident, leading users
1250+
to expect that it works, rather than doing so intentionally as a feature.
1251+
1252+
See https://github.com/pytest-dev/pytest-asyncio/issues/180 for more context.
1253+
"""
1254+
testdir.copy_example("unittest/test_unittest_plain_async.py")
1255+
result = testdir.runpytest_subprocess()
1256+
result.stdout.fnmatch_lines(
1257+
["*RuntimeWarning: coroutine * was never awaited", "*1 passed*"]
1258+
)

0 commit comments

Comments
 (0)