From 837992767e2a1f4c9e2d38ce5839fd7262b12100 Mon Sep 17 00:00:00 2001 From: Paulo Romeira Date: Thu, 4 Jun 2020 16:12:48 -0300 Subject: [PATCH] aiohttp: Fix tests --- tests/integration/test_aiohttp.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index e389270..14909a3 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -1,4 +1,3 @@ -import asyncio import contextlib import logging import urllib.parse @@ -324,7 +323,7 @@ def test_double_requests(tmpdir): def test_cookies(scheme, tmpdir): - async def run(scheme, tmpdir): + async def run(loop): cookies_url = scheme + ( "://httpbin.org/response-headers?" "set-cookie=" + urllib.parse.quote("cookie_1=val_1; Path=/") + "&" @@ -337,16 +336,18 @@ def test_cookies(scheme, tmpdir): # ------------------------- Record -------------------------- # with vcr.use_cassette(tmp) as cassette: - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(loop=loop) as session: cookies_resp = await session.get(cookies_url) home_resp = await session.get(home_url, cookies=req_cookies, headers=req_headers) + assert cassette.play_count == 0 assert_responses(cookies_resp, home_resp) # -------------------------- Play --------------------------- # with vcr.use_cassette(tmp, record_mode="none") as cassette: - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(loop=loop) as session: cookies_resp = await session.get(cookies_url) home_resp = await session.get(home_url, cookies=req_cookies, headers=req_headers) + assert cassette.play_count == 2 assert_responses(cookies_resp, home_resp) def assert_responses(cookies_resp, home_resp): @@ -358,4 +359,4 @@ def test_cookies(scheme, tmpdir): assert "Cookie_3=Val_3" in request_cookies assert "Cookie_4=Val_4" in request_cookies - asyncio.run(run(scheme, tmpdir)) + run_in_loop(run)