diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 150708b..41c9be2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,7 @@ jobs: flake8 jsonrpc_async tests.py - name: Test with pytest run: | - pytest --cov-report term-missing --cov=jsonrpc_async tests.py + pytest --cov-report term-missing --cov=jsonrpc_async --asyncio-mode=auto tests.py - name: Coveralls uses: AndreMiras/coveralls-python-action@develop with: diff --git a/README.rst b/README.rst index 94ffa61..41a9d2d 100644 --- a/README.rst +++ b/README.rst @@ -28,14 +28,11 @@ Execute remote JSON-RPC functions from jsonrpc_async import Server async def routine(): - server = Server('http://localhost:8080') - try: + async with Server('http://localhost:8080') as server: await server.foo(1, 2) await server.foo(bar=1, baz=2) await server.foo({'foo': 'bar'}) await server.foo.bar(baz=1, qux=2) - finally: - await server.session.close() asyncio.get_event_loop().run_until_complete(routine()) @@ -47,11 +44,8 @@ A notification from jsonrpc_async import Server async def routine(): - server = Server('http://localhost:8080') - try: + async with Server('http://localhost:8080') as server: await server.foo(bar=1, _notification=True) - finally: - await server.session.close() asyncio.get_event_loop().run_until_complete(routine()) @@ -64,14 +58,12 @@ Pass through arguments to aiohttp (see also `aiohttp documentation