diff --git a/testing/example_scripts/unittest/test_unittest_plain_async.py b/testing/example_scripts/unittest/test_unittest_plain_async.py new file mode 100644 index 000000000..78dfece68 --- /dev/null +++ b/testing/example_scripts/unittest/test_unittest_plain_async.py @@ -0,0 +1,6 @@ +import unittest + + +class Test(unittest.TestCase): + async def test_foo(self): + assert False diff --git a/testing/test_unittest.py b/testing/test_unittest.py index f9455e63b..26fbf41cf 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -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*"] + )