Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
remove run_loop tests marker
Browse files Browse the repository at this point in the history
  • Loading branch information
popravich committed Nov 18, 2019
1 parent de36e3f commit c18c96b
Show file tree
Hide file tree
Showing 26 changed files with 21 additions and 388 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -3,7 +3,7 @@ minversion = 2.9.1
addopts = -r a --cov-report=term --cov-report=html
restpaths = tests
markers =
run_loop: Mark coroutine to be run with asyncio loop.
timeout: Set coroutine execution timeout (default is 15 seconds).
redis_version(*version, reason): Mark test expecting minimum Redis version
skip(reason): Skip test
python_files =
Expand Down
27 changes: 11 additions & 16 deletions tests/conftest.py
Expand Up @@ -9,6 +9,7 @@
import time
import tempfile
import atexit
import inspect

from collections import namedtuple
from urllib.parse import urlencode, urlunparse
Expand Down Expand Up @@ -529,33 +530,27 @@ def run(*commandline, _clear_tmp_files=(), **kwargs):
pass


@pytest.mark.tryfirst
def pytest_pycollect_makeitem(collector, name, obj):
if collector.funcnamefilter(name):
if not callable(obj):
return
item = pytest.Function(name, parent=collector)
if item.get_closest_marker('run_loop') is not None:
# TODO: re-wrap with asyncio.coroutine if not native coroutine
return list(collector._genfunctions(name, obj))


@pytest.mark.tryfirst
def pytest_pyfunc_call(pyfuncitem):
"""
Run asyncio marked test functions in an event loop instead of a normal
function call.
"""
marker = pyfuncitem.get_closest_marker('run_loop')
if marker is not None:
if inspect.iscoroutinefunction(pyfuncitem.obj):
marker = pyfuncitem.get_closest_marker('timeout')
if marker is not None and marker.args:
timeout = marker.args[0]
else:
timeout = 15

funcargs = pyfuncitem.funcargs
loop = funcargs['loop']
testargs = {arg: funcargs[arg]
for arg in pyfuncitem._fixtureinfo.argnames}

loop.run_until_complete(
_wait_coro(pyfuncitem.obj, testargs,
timeout=marker.kwargs.get('timeout', 15),
timeout=timeout,
loop=loop))
return True

Expand All @@ -566,8 +561,8 @@ async def _wait_coro(corofunc, kwargs, timeout, loop):


def pytest_runtest_setup(item):
run_loop = item.get_closest_marker('run_loop')
if run_loop and 'loop' not in item.fixturenames:
is_coro = inspect.iscoroutinefunction(item.obj)
if is_coro and 'loop' not in item.fixturenames:
# inject an event loop fixture for all async tests
item.fixturenames.append('loop')

Expand Down
9 changes: 0 additions & 9 deletions tests/connection_commands_test.py
Expand Up @@ -7,7 +7,6 @@
from _testutils import redis_version


@pytest.mark.run_loop
async def test_repr(create_redis, loop, server):
redis = await create_redis(
server.tcp_address, db=1, loop=loop)
Expand All @@ -24,14 +23,12 @@ async def test_repr(create_redis, loop, server):
}


@pytest.mark.run_loop
async def test_auth(redis):
expected_message = "ERR Client sent AUTH, but no password is set"
with pytest.raises(ReplyError, match=expected_message):
await redis.auth('')


@pytest.mark.run_loop
async def test_echo(redis):
resp = await redis.echo('ECHO')
assert resp == b'ECHO'
Expand All @@ -40,12 +37,10 @@ async def test_echo(redis):
await redis.echo(None)


@pytest.mark.run_loop
async def test_ping(redis):
assert await redis.ping() == b'PONG'


@pytest.mark.run_loop
async def test_quit(redis, loop):
expected = (ConnectionClosedError, ConnectionError)
try:
Expand All @@ -70,7 +65,6 @@ async def test_quit(redis, loop):
await redis.ping()


@pytest.mark.run_loop
async def test_select(redis):
assert redis.db == 0

Expand All @@ -80,7 +74,6 @@ async def test_select(redis):
assert redis.connection.db == 1


@pytest.mark.run_loop
async def test_encoding(create_redis, loop, server):
redis = await create_redis(
server.tcp_address,
Expand All @@ -89,7 +82,6 @@ async def test_encoding(create_redis, loop, server):
assert redis.encoding == 'utf-8'


@pytest.mark.run_loop
async def test_yield_from_backwards_compatibility(create_redis, server, loop):
redis = await create_redis(server.tcp_address, loop=loop)

Expand All @@ -103,7 +95,6 @@ async def test_yield_from_backwards_compatibility(create_redis, server, loop):


@redis_version(4, 0, 0, reason="SWAPDB is available since redis>=4.0.0")
@pytest.mark.run_loop
async def test_swapdb(create_redis, start_server, loop):
server = start_server('swapdb_1')
cli1 = await create_redis(server.tcp_address, db=0, loop=loop)
Expand Down
29 changes: 0 additions & 29 deletions tests/connection_test.py
Expand Up @@ -17,7 +17,6 @@
from _testutils import redis_version


@pytest.mark.run_loop
async def test_connect_tcp(request, create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand All @@ -36,7 +35,6 @@ async def test_connect_tcp(request, create_connection, loop, server):
assert str(conn) == '<RedisConnection [db:0]>'


@pytest.mark.run_loop
async def test_connect_inject_connection_cls(
request,
create_connection,
Expand All @@ -52,7 +50,6 @@ class MyConnection(RedisConnection):
assert isinstance(conn, MyConnection)


@pytest.mark.run_loop
async def test_connect_inject_connection_cls_invalid(
request,
create_connection,
Expand All @@ -64,7 +61,6 @@ async def test_connect_inject_connection_cls_invalid(
server.tcp_address, loop=loop, connection_cls=type)


@pytest.mark.run_loop
async def test_connect_tcp_timeout(request, create_connection, loop, server):
with patch.object(loop, 'create_connection') as\
open_conn_mock:
Expand All @@ -74,15 +70,13 @@ async def test_connect_tcp_timeout(request, create_connection, loop, server):
server.tcp_address, loop=loop, timeout=0.1)


@pytest.mark.run_loop
async def test_connect_tcp_invalid_timeout(
request, create_connection, loop, server):
with pytest.raises(ValueError):
await create_connection(
server.tcp_address, loop=loop, timeout=0)


@pytest.mark.run_loop
@pytest.mark.skipif(sys.platform == 'win32',
reason="No unixsocket on Windows")
async def test_connect_unixsocket(create_connection, loop, server):
Expand All @@ -93,7 +87,6 @@ async def test_connect_unixsocket(create_connection, loop, server):
assert str(conn) == '<RedisConnection [db:0]>'


@pytest.mark.run_loop
@pytest.mark.skipif(sys.platform == 'win32',
reason="No unixsocket on Windows")
async def test_connect_unixsocket_timeout(create_connection, loop, server):
Expand All @@ -104,7 +97,6 @@ async def test_connect_unixsocket_timeout(create_connection, loop, server):
server.unixsocket, db=0, loop=loop, timeout=0.1)


@pytest.mark.run_loop
@redis_version(2, 8, 0, reason="maxclients config setting")
async def test_connect_maxclients(create_connection, loop, start_server):
server = start_server('server-maxclients')
Expand All @@ -128,7 +120,6 @@ def test_global_loop(create_connection, loop, server):
# assert conn._loop is loop


@pytest.mark.run_loop
async def test_select_db(create_connection, loop, server):
address = server.tcp_address
conn = await create_connection(address, loop=loop)
Expand Down Expand Up @@ -159,7 +150,6 @@ async def test_select_db(create_connection, loop, server):
assert conn.db == 1


@pytest.mark.run_loop
async def test_protocol_error(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand Down Expand Up @@ -195,7 +185,6 @@ def test_close_connection__tcp(create_connection, loop, server):
conn.execute_pubsub('subscribe', 'channel:1')


@pytest.mark.run_loop
@pytest.mark.skipif(sys.platform == 'win32',
reason="No unixsocket on Windows")
async def test_close_connection__socket(create_connection, loop, server):
Expand All @@ -212,7 +201,6 @@ async def test_close_connection__socket(create_connection, loop, server):
await conn.execute_pubsub('subscribe', 'channel:1')


@pytest.mark.run_loop
async def test_closed_connection_with_none_reader(
create_connection, loop, server):
address = server.tcp_address
Expand All @@ -233,7 +221,6 @@ async def test_closed_connection_with_none_reader(
conn.close()


@pytest.mark.run_loop
async def test_wait_closed(create_connection, loop, server):
address = server.tcp_address
conn = await create_connection(address, loop=loop)
Expand All @@ -244,7 +231,6 @@ async def test_wait_closed(create_connection, loop, server):
assert reader_task.done()


@pytest.mark.run_loop
async def test_cancel_wait_closed(create_connection, loop, server):
# Regression test: Don't throw error if wait_closed() is cancelled.
address = server.tcp_address
Expand All @@ -261,7 +247,6 @@ async def test_cancel_wait_closed(create_connection, loop, server):
assert reader_task.done()


@pytest.mark.run_loop
async def test_auth(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand Down Expand Up @@ -290,7 +275,6 @@ async def test_auth(create_connection, loop, server):
assert res == b'OK'


@pytest.mark.run_loop
async def test_decoding(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, encoding='utf-8', loop=loop)
Expand Down Expand Up @@ -320,7 +304,6 @@ async def test_decoding(create_connection, loop, server):
assert res == 'значение'


@pytest.mark.run_loop
async def test_execute_exceptions(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand All @@ -333,7 +316,6 @@ async def test_execute_exceptions(create_connection, loop, server):
assert len(conn._waiters) == 0


@pytest.mark.run_loop
async def test_subscribe_unsubscribe(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand Down Expand Up @@ -364,7 +346,6 @@ async def test_subscribe_unsubscribe(create_connection, loop, server):
assert conn.in_pubsub == 1


@pytest.mark.run_loop
async def test_psubscribe_punsubscribe(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand All @@ -373,7 +354,6 @@ async def test_psubscribe_punsubscribe(create_connection, loop, server):
assert conn.in_pubsub == 1


@pytest.mark.run_loop
async def test_bad_command_in_pubsub(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop)
Expand All @@ -388,7 +368,6 @@ async def test_bad_command_in_pubsub(create_connection, loop, server):
conn.execute('get')


@pytest.mark.run_loop
async def test_pubsub_messages(create_connection, loop, server):
sub = await create_connection(
server.tcp_address, loop=loop)
Expand Down Expand Up @@ -425,7 +404,6 @@ async def test_pubsub_messages(create_connection, loop, server):
assert msg == b'Hello!'


@pytest.mark.run_loop
async def test_multiple_subscribe_unsubscribe(create_connection, loop, server):
sub = await create_connection(server.tcp_address, loop=loop)

Expand Down Expand Up @@ -455,7 +433,6 @@ async def test_multiple_subscribe_unsubscribe(create_connection, loop, server):
assert res == [[b'punsubscribe', b'chan:*', 0]]


@pytest.mark.run_loop
async def test_execute_pubsub_errors(create_connection, loop, server):
sub = await create_connection(
server.tcp_address, loop=loop)
Expand All @@ -482,7 +459,6 @@ async def test_execute_pubsub_errors(create_connection, loop, server):
Channel('chan:1', is_pattern=False, loop=loop))


@pytest.mark.run_loop
async def test_multi_exec(create_connection, loop, server):
conn = await create_connection(server.tcp_address, loop=loop)

Expand All @@ -504,7 +480,6 @@ async def test_multi_exec(create_connection, loop, server):
assert res == b'OK'


@pytest.mark.run_loop
async def test_multi_exec__enc(create_connection, loop, server):
conn = await create_connection(
server.tcp_address, loop=loop, encoding='utf-8')
Expand All @@ -527,7 +502,6 @@ async def test_multi_exec__enc(create_connection, loop, server):
assert res == 'OK'


@pytest.mark.run_loop
async def test_connection_parser_argument(create_connection, server, loop):
klass = mock.MagicMock()
klass.return_value = reader = mock.Mock()
Expand All @@ -548,7 +522,6 @@ def feed_gets(data, **kwargs):
assert b'+PONG\r\n' == await conn.execute('ping')


@pytest.mark.run_loop
async def test_connection_idle_close(create_connection, start_server, loop):
server = start_server('idle')
conn = await create_connection(server.tcp_address, loop=loop)
Expand All @@ -566,7 +539,6 @@ async def test_connection_idle_close(create_connection, start_server, loop):
{'db': 1},
{'encoding': 'utf-8'},
], ids=repr)
@pytest.mark.run_loop
async def test_create_connection__tcp_url(
create_connection, server_tcp_url, loop, kwargs):
url = server_tcp_url(**kwargs)
Expand All @@ -586,7 +558,6 @@ async def test_create_connection__tcp_url(
{'db': 1},
{'encoding': 'utf-8'},
], ids=repr)
@pytest.mark.run_loop
async def test_create_connection__unix_url(
create_connection, server_unix_url, loop, kwargs):
url = server_unix_url(**kwargs)
Expand Down

0 comments on commit c18c96b

Please sign in to comment.