Demonstrate that plain unittest does not support async tests (#7607)

Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
Bruno Oliveira 2020-08-04 19:37:41 -03:00 committed by GitHub
parent 2bd0d97fcc
commit 44cd8a3a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,6 @@
import unittest
class Test(unittest.TestCase):
async def test_foo(self):
assert False

View File

@ -1241,3 +1241,18 @@ def test_asynctest_support(testdir):
testdir.copy_example("unittest/test_unittest_asynctest.py")
reprec = testdir.inline_run()
reprec.assertoutcome(failed=1, passed=2)
def test_plain_unittest_does_not_support_async(testdir):
"""Async functions in plain unittest.TestCase subclasses are not supported without plugins.
This test exists here to avoid introducing this support by accident, leading users
to expect that it works, rather than doing so intentionally as a feature.
See https://github.com/pytest-dev/pytest-asyncio/issues/180 for more context.
"""
testdir.copy_example("unittest/test_unittest_plain_async.py")
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(
["*RuntimeWarning: coroutine * was never awaited", "*1 passed*"]
)