diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 9662ac6..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,6 +0,0 @@ -import pytest - -# TODO This fixture is depricated and should be removed. It is used to support tests for aiohttp 2.3.x -@pytest.fixture -def aiohttp_client(test_client): - return test_client \ No newline at end of file diff --git a/tests/test_openapi.py b/tests/test_openapi.py index b21bd0b..9e4a5a7 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -93,10 +93,10 @@ async def ping_partial(request): return web.Response(text="pong") -async def test_swagger_ui(aiohttp_client, loop): +async def test_swagger_ui(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) setup_swagger(app, swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml", ui_version=3 @@ -113,10 +113,10 @@ async def test_swagger_ui(aiohttp_client, loop): assert retrieved == loaded -async def test_swagger_file_url(aiohttp_client, loop): +async def test_swagger_file_url(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) setup_swagger(app, ui_version=3, swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml") @@ -129,9 +129,8 @@ async def test_swagger_file_url(aiohttp_client, loop): assert '/example2' in result['paths'] assert 'API Title' in result['info']['title'] - -async def test_partial_swagger_file(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_partial_swagger_file(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping-partial", ping_partial) setup_swagger(app, ui_version=3) @@ -141,9 +140,8 @@ async def test_partial_swagger_file(aiohttp_client, loop): result = await resp1.json() assert '/ping-partial' in result['paths'] - -async def test_custom_swagger(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_custom_swagger(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -161,9 +159,8 @@ async def test_custom_swagger(aiohttp_client, loop): assert '/ping' in result['paths'] assert 'Test Custom Title' in result['info']['title'] - -async def test_swagger_home_decorator(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_swagger_home_decorator(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -183,8 +180,8 @@ async def test_swagger_home_decorator(aiohttp_client, loop): assert 'Test Custom Title' in result['info']['title'] -async def test_swagger_def_decorator(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_swagger_def_decorator(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -210,8 +207,8 @@ def swagger_info(): return yaml.full_load(open(filename).read()) -async def test_swagger_info(aiohttp_client, loop, swagger_info): - app = web.Application(loop=loop) +async def test_swagger_info(aiohttp_client, event_loop, swagger_info): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -228,8 +225,8 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info): assert 'API Title' in result['info']['title'] -async def test_undocumented_fn(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_undocumented_fn(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/undoc_ping", undoc_ping) setup_swagger(app, ui_version=3) client = await aiohttp_client(app) @@ -241,8 +238,8 @@ async def test_undocumented_fn(aiohttp_client, loop): assert not result['paths'] -async def test_wrong_method(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_wrong_method(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('POST', "/post_ping", ping) setup_swagger(app, ui_version=3) client = await aiohttp_client(app) @@ -256,8 +253,8 @@ async def test_wrong_method(aiohttp_client, loop): assert resp.status == 405 -async def test_class_view(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_class_view(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('*', "/class_view", ClassView) setup_swagger(app, ui_version=3) @@ -294,10 +291,10 @@ async def test_class_view(aiohttp_client, loop): assert "patch" not in result['paths']["/class_view"] -async def test_data_defs(aiohttp_client, loop): +async def test_data_defs(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) file = open(TESTS_PATH + "/data/example_data_definitions.json") - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) app.router.add_route('GET', "/users", users_with_data_def) setup_swagger(app, ui_version=3, definitions=json.loads(file.read())) file.close() @@ -311,11 +308,11 @@ async def test_data_defs(aiohttp_client, loop): assert result['components']['schemas']['User']['properties']['permissions']['items']['$ref'] is not None -async def test_sub_app(aiohttp_client, loop): - sub_app = web.Application(loop=loop) +async def test_sub_app(aiohttp_client, event_loop): + sub_app = web.Application(loop=event_loop) sub_app.router.add_route('*', "/class_view", ClassView) setup_swagger(sub_app, ui_version=3, api_base_url='/sub_app') - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) app.add_subapp(prefix='/sub_app', subapp=sub_app) client = await aiohttp_client(app) diff --git a/tests/test_swagger.py b/tests/test_swagger.py index 3001fbc..8a19766 100644 --- a/tests/test_swagger.py +++ b/tests/test_swagger.py @@ -93,8 +93,8 @@ async def ping_partial(request): return web.Response(text="pong") -async def test_ping(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_ping(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) client = await aiohttp_client(app) resp = await client.get('/ping') @@ -103,11 +103,11 @@ async def test_ping(aiohttp_client, loop): assert 'pong' in text -async def test_swagger_ui(aiohttp_client, loop): +async def test_swagger_ui(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) setup_swagger(app, swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml") @@ -122,10 +122,10 @@ async def test_swagger_ui(aiohttp_client, loop): assert retrieved == loaded -async def test_swagger_ui3(aiohttp_client, loop): +async def test_swagger_ui3(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) setup_swagger(app, swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml", ui_version=3 @@ -142,10 +142,10 @@ async def test_swagger_ui3(aiohttp_client, loop): assert retrieved == loaded -async def test_swagger_file_url(aiohttp_client, loop): +async def test_swagger_file_url(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) setup_swagger(app, swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml") @@ -158,8 +158,8 @@ async def test_swagger_file_url(aiohttp_client, loop): assert 'API Title' in result['info']['title'] -async def test_partial_swagger_file(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_partial_swagger_file(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping-partial", ping_partial) setup_swagger(app) @@ -170,8 +170,8 @@ async def test_partial_swagger_file(aiohttp_client, loop): assert '/ping-partial' in result['paths'] -async def test_custom_swagger(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_custom_swagger(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -189,8 +189,8 @@ async def test_custom_swagger(aiohttp_client, loop): assert 'Test Custom Title' in result['info']['title'] -async def test_swagger_home_decorator(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_swagger_home_decorator(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -209,8 +209,8 @@ async def test_swagger_home_decorator(aiohttp_client, loop): assert 'Test Custom Title' in result['info']['title'] -async def test_swagger_def_decorator(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_swagger_def_decorator(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -235,8 +235,8 @@ def swagger_info(): return yaml.full_load(open(filename).read()) -async def test_swagger_info(aiohttp_client, loop, swagger_info): - app = web.Application(loop=loop) +async def test_swagger_info(aiohttp_client, event_loop, swagger_info): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/ping", ping) description = "Test Custom Swagger" setup_swagger(app, @@ -252,8 +252,8 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info): assert 'API Title' in result['info']['title'] -async def test_undocumented_fn(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_undocumented_fn(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/undoc_ping", undoc_ping) setup_swagger(app) client = await aiohttp_client(app) @@ -265,8 +265,8 @@ async def test_undocumented_fn(aiohttp_client, loop): assert not result['paths'] -async def test_wrong_method(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_wrong_method(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('POST', "/post_ping", ping) setup_swagger(app) client = await aiohttp_client(app) @@ -279,8 +279,8 @@ async def test_wrong_method(aiohttp_client, loop): resp = await client.get('/post_ping') assert resp.status == 405 -async def test_class_view_single_method(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_class_view_single_method(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('GET', "/class_view", ClassView) setup_swagger(app) @@ -303,8 +303,8 @@ async def test_class_view_single_method(aiohttp_client, loop): assert "post" not in result['paths']["/class_view"] -async def test_class_view_multiple_methods(aiohttp_client, loop): - app = web.Application(loop=loop) +async def test_class_view_multiple_methods(aiohttp_client, event_loop): + app = web.Application(loop=event_loop) app.router.add_route('*', "/class_view", ClassView) setup_swagger(app) @@ -341,10 +341,10 @@ async def test_class_view_multiple_methods(aiohttp_client, loop): assert "patch" not in result['paths']["/class_view"] -async def test_data_defs(aiohttp_client, loop): +async def test_data_defs(aiohttp_client, event_loop): TESTS_PATH = abspath(join(dirname(__file__))) file = open(TESTS_PATH + "/data/example_data_definitions.json") - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) app.router.add_route('GET', "/users", users_with_data_def) setup_swagger(app, definitions=json.loads(file.read())) file.close() @@ -358,11 +358,11 @@ async def test_data_defs(aiohttp_client, loop): assert result['definitions']['User']['properties']['permissions']['items']['$ref'] is not None -async def test_sub_app(aiohttp_client, loop): - sub_app = web.Application(loop=loop) +async def test_sub_app(aiohttp_client, event_loop): + sub_app = web.Application(loop=event_loop) sub_app.router.add_route('*', "/class_view", ClassView) setup_swagger(sub_app, api_base_url='/sub_app') - app = web.Application(loop=loop) + app = web.Application(loop=event_loop) app.add_subapp(prefix='/sub_app', subapp=sub_app) client = await aiohttp_client(app) diff --git a/tox.ini b/tox.ini index f10c116..34462a1 100644 --- a/tox.ini +++ b/tox.ini @@ -3,4 +3,7 @@ envlist = py35, py36, py37, py38 [testenv] deps = -rrequirements-dev.txt -commands = py.test \ No newline at end of file +commands = py.test + +[pytest] +asyncio-default-fixture-loop-scope=function