import asyncio
import pytest

def test_hello_world(workspace):
    workspace.src('main.py', r"""
    import asyncio

    async def main():
        print('Hello, ', end='')
        await asyncio.sleep(1)
        print('World!')

    # Python 3.7+
    asyncio.run(main())
    """)

    r = workspace.run('python main.py')
    assert r.out == 'Hello, World!'

@pytest.mark.asyncio
async def test_hello_world__pytest_asyncio(workspace):
    result = await async_task('World')
    assert result == 'Hello, World!'

async def async_task(input):
    await asyncio.sleep(1)
    return 'Hello, %s!' % input

def test_import_asyncio_not_needed_for_using_async_await_keywords(workspace):
    workspace.src('main.py', r"""
    async def main():
        pass

    print(type(main()))
    """)

    r = workspace.run('python main.py')
    assert r.out == "<class 'coroutine'>"
    assert r.err == "main.py:4: RuntimeWarning: coroutine 'main' was never awaited\n  print(type(main()))"


@@ -128,122 +128,343 @@
 def 
-main():%0A        print('Hello, ', end='')%0A        await asyncio.sleep(1)%0A        print('World!')%0A%0A    # Python 3.7+
+do_something_else():%0A        print('...', end='')%0A        await asyncio.sleep(1)%0A        print('!', end='')%0A%0A    async def say_hello_async(who):%0A        print('Hello, ', end='')%0A        await asyncio.sleep(1)%0A        print(who, end='')%0A%0A    async def main():%0A        await asyncio.gather(say_hello_async('World'), do_something_else())%0A
 %0A   
@@ -554,32 +554,35 @@
 .out == 'Hello, 
+...
 World!'%0A%0A@pytest
@@ -642,184 +642,410 @@
 cio(
-workspace):%0A    result = await async_task('World
+capsys):%0A    async def do_something_else():%0A        print('...', end='')%0A        await asyncio.sleep(1)%0A        print('!', end='
 ')%0A
+%0A
     as
-sert result == 'Hello, World!'%0A%0Aasync def async_task(input):%0A    await asyncio.sleep(1)%0A    return 'Hello, %25s!' %25 input
+ync def say_hello_async(who):%0A        print('Hello, ', end='')%0A        await asyncio.sleep(1)%0A        print(who, end='')%0A%0A    await asyncio.gather(say_hello_async('World'), do_something_else())%0A%0A    out, _ = capsys.readouterr()%0A    assert out == 'Hello, ...World!'
 %0A%0Ade

Make hello world (asyncio) more involved