Skip to content

Commit

Permalink
Enable tests on 3.8+ (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Nov 10, 2021
1 parent f975fbc commit 0735b62
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
Expand Down
5 changes: 3 additions & 2 deletions aiohttp_session/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def __init__(
)
if aioredis is None:
raise RuntimeError("Please install aioredis")
if StrictVersion(aioredis.__version__).version < (1, 0):
raise RuntimeError("aioredis<1.0 is not supported")
# May have installed aioredis separately (without aiohttp-session[aioredis]).
if StrictVersion(aioredis.__version__).version < (2, 0):
raise RuntimeError("aioredis<2.0 is not supported")
self._key_factory = key_factory
if not isinstance(redis_pool, aioredis.Redis):
raise TypeError(f"Expected aioredis.Redis got {type(redis_pool)}")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def read(f):

install_requires = ["aiohttp>=3.8", 'typing_extensions>=3.7.4; python_version<"3.8"']
extras_require = {
"aioredis": ["aioredis>=1.0.0"],
"aioredis": ["aioredis>=2.0.0"],
"aiomcache": ["aiomcache>=0.5.2"],
"pycrypto": ["cryptography"],
"secure": ["cryptography"],
Expand Down
20 changes: 15 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from typing_extensions import TypedDict


# TODO: Remove once fixed: https://github.com/aio-libs/aioredis-py/issues/1115
aioredis.Redis.__del__ = lambda *args: None # type: ignore


class _ContainerInfo(TypedDict):
host: str
port: int
Expand Down Expand Up @@ -61,7 +65,8 @@ def session_id() -> str:
@pytest.fixture(scope="session")
def docker() -> DockerClient: # type: ignore[misc] # No docker types.
client = docker_from_env(version="auto")
return client
yield client
client.close()


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -107,6 +112,10 @@ def redis_server( # type: ignore[misc] # No docker types.
except ConnectionError:
time.sleep(delay)
delay *= 2
finally:
loop.run_until_complete(conn.close())
# TODO: Remove once fixed: github.com/aio-libs/aioredis-py/issues/1103
loop.run_until_complete(conn.connection_pool.disconnect())
else:
pytest.fail("Cannot start redis server")

Expand All @@ -133,9 +142,8 @@ async def start(pool: aioredis.ConnectionPool) -> aioredis.Redis:
pool = aioredis.ConnectionPool.from_url(redis_url)
redis = loop.run_until_complete(start(pool))
yield redis
if redis is not None:
redis.close() # type: ignore[no-untyped-call]
loop.run_until_complete(pool.disconnect())
loop.run_until_complete(redis.close()) # type: ignore[no-untyped-call]
loop.run_until_complete(pool.disconnect())


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -181,6 +189,8 @@ def memcached_server( # type: ignore[misc] # No docker types.
except ConnectionRefusedError:
time.sleep(delay)
delay *= 2
finally:
loop.run_until_complete(conn.close())
else:
pytest.fail("Cannot start memcached server")

Expand All @@ -203,4 +213,4 @@ def memcached( # type: ignore[misc]
) -> Iterator[aiomcache.Client]:
conn = aiomcache.Client(loop=loop, **memcached_params)
yield conn
conn.close()
loop.run_until_complete(conn.close())
1 change: 1 addition & 0 deletions tests/test_redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ async def handler(request: web.Request) -> web.StreamResponse:

redis = aioredis.from_url(redis_url) # type: ignore[no-untyped-call]
create_app(handler=handler, redis=redis)
await redis.close()


async def test_not_redis_provided_to_storage() -> None:
Expand Down

0 comments on commit 0735b62

Please sign in to comment.