Skip to content

Commit

Permalink
refactor(tests): drop pytest-asyncio (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 authored Aug 21, 2024
1 parent fbba897 commit a65d807
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 82 deletions.
1 change: 0 additions & 1 deletion requirements/cibwtest
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
msgpack
pytest
pytest-asyncio<0.22.0
pyyaml
requests
1 change: 0 additions & 1 deletion requirements/mintest
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
coverage>=4.1
pytest
pytest-asyncio<0.22.0
requests
2 changes: 0 additions & 2 deletions requirements/tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ requests
testtools; python_version < '3.10'

# ASGI Specific (daphne is installed on a its own tox env)
# TODO(vytas): Some ASGI tests hang with pytest-asyncio-0.23 on 3.8 & 3.9.
pytest-asyncio < 0.22.0
aiofiles
httpx
uvicorn >= 0.17.0
Expand Down
4 changes: 0 additions & 4 deletions tests/asgi/test_asgi_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from falcon.asgi import App


@pytest.mark.asyncio
async def test_default_headers():
class Resource:
async def on_get(self, req, resp):
Expand All @@ -21,7 +20,6 @@ async def on_get(self, req, resp):


@pytest.mark.parametrize('simulate_method', ['request', 'simulate_request'])
@pytest.mark.asyncio
async def test_generic_request(simulate_method):
class Resource:
async def on_lock(self, req, resp):
Expand All @@ -37,7 +35,6 @@ async def on_lock(self, req, resp):
assert result.status_code == 422


@pytest.mark.asyncio
async def test_wsgi_not_supported():
with pytest.raises(falcon.CompatibilityError):
async with testing.TestClient(falcon.App()):
Expand All @@ -52,7 +49,6 @@ async def test_wsgi_not_supported():
'method', ['get', 'head', 'post', 'put', 'options', 'patch', 'delete']
)
@pytest.mark.parametrize('use_alias', ['alias', 'simulate'])
@pytest.mark.asyncio
async def test_responders(method, use_alias):
class Resource:
async def on_get(self, req, resp):
Expand Down
2 changes: 0 additions & 2 deletions tests/asgi/test_asgi_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import inspect

import falcon
from falcon.asgi import _asgi_helpers


Expand All @@ -15,7 +14,6 @@ async def _call_factory(self, scope, receive, send):
__call__ = _asgi_helpers._wrap_asgi_coroutine_func(unorthodox_call)


@falcon.runs_sync
async def test_intricate_app():
async def receive():
pass
Expand Down
14 changes: 0 additions & 14 deletions tests/asgi/test_asgi_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def test_sse_client_disconnects_early(self, server_base_url):
timeout=(_asgi_test_app.SSE_TEST_MAX_DELAY_SEC / 2),
)

@pytest.mark.asyncio
@pytest.mark.skipif(httpx is None, reason='httpx is required for this test')
async def test_stream_chunked_request(self, server_base_url):
"""Regression test for https://github.com/falconry/falcon/issues/2024"""
Expand All @@ -197,7 +196,6 @@ async def emitter():
websockets is None, reason='websockets is required for this test class'
)
class TestWebSocket:
@pytest.mark.asyncio
@pytest.mark.parametrize('explicit_close', [True, False])
@pytest.mark.parametrize('close_code', [None, 4321])
async def test_hello(self, explicit_close, close_code, server_url_events_ws):
Expand Down Expand Up @@ -242,7 +240,6 @@ async def test_hello(self, explicit_close, close_code, server_url_events_ws):

assert got_message

@pytest.mark.asyncio
@pytest.mark.parametrize('explicit_close', [True, False])
@pytest.mark.parametrize('close_code', [None, 4040])
async def test_rejected(self, explicit_close, close_code, server_url_events_ws):
Expand All @@ -261,7 +258,6 @@ async def test_rejected(self, explicit_close, close_code, server_url_events_ws):

assert exc_info.value.status_code == 403

@pytest.mark.asyncio
async def test_missing_responder(self, server_url_events_ws):
server_url_events_ws += '/404'

Expand All @@ -271,7 +267,6 @@ async def test_missing_responder(self, server_url_events_ws):

assert exc_info.value.status_code == 403

@pytest.mark.asyncio
@pytest.mark.parametrize(
'subprotocol, expected',
[
Expand All @@ -290,7 +285,6 @@ async def test_select_subprotocol_known(
) as ws:
assert ws.subprotocol == expected

@pytest.mark.asyncio
async def test_select_subprotocol_unknown(self, server_url_events_ws):
extra_headers = {'X-Subprotocol': 'xmpp'}

Expand Down Expand Up @@ -322,7 +316,6 @@ async def test_select_subprotocol_unknown(self, server_url_events_ws):
# tried to capture this output and check it in the test below,
# but the usual ways of capturing stdout/stderr with pytest do
# not work.
@pytest.mark.asyncio
async def test_disconnecting_client_early(self, server_url_events_ws):
ws = await websockets.connect(
server_url_events_ws, extra_headers={'X-Close': 'True'}
Expand All @@ -342,7 +335,6 @@ async def test_disconnecting_client_early(self, server_url_events_ws):
# messages after the close.
await asyncio.sleep(1)

@pytest.mark.asyncio
async def test_send_before_accept(self, server_url_events_ws):
extra_headers = {'x-accept': 'skip'}

Expand All @@ -352,7 +344,6 @@ async def test_send_before_accept(self, server_url_events_ws):
message = await ws.recv()
assert message == 'OperationNotAllowed'

@pytest.mark.asyncio
async def test_recv_before_accept(self, server_url_events_ws):
extra_headers = {'x-accept': 'skip', 'x-command': 'recv'}

Expand All @@ -362,7 +353,6 @@ async def test_recv_before_accept(self, server_url_events_ws):
message = await ws.recv()
assert message == 'OperationNotAllowed'

@pytest.mark.asyncio
async def test_invalid_close_code(self, server_url_events_ws):
extra_headers = {'x-close': 'True', 'x-close-code': 42}

Expand All @@ -379,7 +369,6 @@ async def test_invalid_close_code(self, server_url_events_ws):
elapsed = time.time() - start
assert elapsed < 2

@pytest.mark.asyncio
async def test_close_code_on_unhandled_error(self, server_url_events_ws):
extra_headers = {'x-raise-error': 'generic'}

Expand All @@ -390,7 +379,6 @@ async def test_close_code_on_unhandled_error(self, server_url_events_ws):

assert ws.close_code in {3011, 1011}

@pytest.mark.asyncio
async def test_close_code_on_unhandled_http_error(self, server_url_events_ws):
extra_headers = {'x-raise-error': 'http'}

Expand All @@ -401,7 +389,6 @@ async def test_close_code_on_unhandled_http_error(self, server_url_events_ws):

assert ws.close_code == 3400

@pytest.mark.asyncio
@pytest.mark.parametrize('mismatch', ['send', 'recv'])
@pytest.mark.parametrize('mismatch_type', ['text', 'data'])
async def test_type_mismatch(self, mismatch, mismatch_type, server_url_events_ws):
Expand All @@ -423,7 +410,6 @@ async def test_type_mismatch(self, mismatch, mismatch_type, server_url_events_ws

assert ws.close_code in {3011, 1011}

@pytest.mark.asyncio
async def test_passing_path_params(self, server_base_url_ws):
expected_feed_id = '1ee7'
url = f'{server_base_url_ws}feeds/{expected_feed_id}'
Expand Down
2 changes: 0 additions & 2 deletions tests/asgi/test_boundedstream_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ async def test_iteration():
falcon.async_to_sync(test_iteration)


@falcon.runs_sync
async def test_iterate_streaming_request():
events = iter(
(
Expand Down Expand Up @@ -274,7 +273,6 @@ async def t():
falcon.async_to_sync(t)


@falcon.runs_sync
async def test_exhaust():
emitter = testing.ASGIRequestEventEmitter(b'123456798' * 1024)
stream = asgi.BoundedStream(emitter)
Expand Down
19 changes: 2 additions & 17 deletions tests/asgi/test_buffered_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def test_basic_aiter(reader1):
]


@falcon.runs_sync
async def test_aiter_from_buffer(reader1):
assert await reader1.read(4) == b'Hell'

Expand Down Expand Up @@ -148,27 +147,23 @@ def test_delimit(reader1, delimiter, expected):
assert async_take(delimited) == expected


@falcon.runs_sync
async def test_exhaust(reader1):
await reader1.exhaust()
assert await reader1.peek() == b''


@pytest.mark.parametrize('size', [1, 2, 3, 5, 7, 8])
@falcon.runs_sync
async def test_peek(reader1, size):
assert await reader1.peek(size) == b'Hello, World'[:size]
assert reader1.tell() == 0


@falcon.runs_sync
async def test_peek_at_eof():
source = chop_data(b'Hello!')
stream = reader.BufferedReader(source)
assert await stream.peek(16) == b'Hello!'


@falcon.runs_sync
async def test_pipe(reader1):
sink = AsyncSink()
await reader1.pipe(sink)
Expand All @@ -177,7 +172,6 @@ async def test_pipe(reader1):
assert reader1.tell() == len(sink.accumulated)


@falcon.runs_sync
async def test_pipe_until_delimiter_not_found(reader1):
sink = AsyncSink()
await reader1.pipe_until(b'404', sink)
Expand All @@ -202,7 +196,6 @@ async def test_pipe_until_delimiter_not_found(reader1):
((50, 1), [b'Hello, World!\nJust testing some iterator goodness.', b'\n']),
],
)
@falcon.runs_sync
async def test_read(reader1, sizes, expected):
results = []
for size in sizes:
Expand All @@ -213,7 +206,6 @@ async def test_read(reader1, sizes, expected):

@pytest.mark.parametrize('start_size', [1, 16777216])
@pytest.mark.slow
@falcon.runs_sync
async def test_varying_read_size(reader2, start_size):
size = start_size
result = io.BytesIO()
Expand All @@ -230,7 +222,6 @@ async def test_varying_read_size(reader2, start_size):


@pytest.mark.parametrize('peek', [0, 1, 8])
@falcon.runs_sync
async def test_readall(reader1, peek):
if peek:
await reader1.peek(peek)
Expand Down Expand Up @@ -263,7 +254,6 @@ async def test_readall(reader1, peek):
(7, b'good', -1, b'World!\nJust testing some iterator '),
],
)
@falcon.runs_sync
async def test_read_until(reader1, offset, delimiter, size, expected, fork):
if offset:
await reader1.read(offset)
Expand All @@ -274,7 +264,6 @@ async def test_read_until(reader1, offset, delimiter, size, expected, fork):
assert await reader1.read_until(delimiter, size) == expected


@falcon.runs_sync
async def test_read_until_with_buffer_edge_case(reader1):
assert await reader1.read(12) == b'Hello, World'
assert await reader1.peek(1) == b'!'
Expand All @@ -292,15 +281,13 @@ def test_placeholder_methods(reader1):
assert not reader1.writable()


@falcon.runs_sync
async def test_iteration_started(reader1):
async for chunk in reader1:
with pytest.raises(OperationNotAllowed):
async for nested in reader1:
pass


@falcon.runs_sync
async def test_invalid_delimiter_length(reader1):
with pytest.raises(ValueError):
await reader1.read_until(b'')
Expand All @@ -320,7 +307,6 @@ async def test_invalid_delimiter_length(reader1):
],
)
@pytest.mark.slow
@falcon.runs_sync
async def test_irregular_large_read_until(reader2, size1, size2):
delimiter = b'--boundary1234567890--'

Expand All @@ -341,7 +327,6 @@ async def test_irregular_large_read_until(reader2, size1, size2):
assert chunk1 + chunk2 + remainder == expected[1337:]


@falcon.runs_sync
@pytest.mark.parametrize('chunk_size', list(range(46, 63)))
async def test_read_until_shared_boundary(chunk_size):
source = chop_data(
Expand All @@ -356,7 +341,8 @@ async def test_read_until_shared_boundary(chunk_size):

# NOTE(vytas): This is woefully unoptimized, and this test highlights that.
# Work in progress.
@falcon.runs_sync


async def test_small_reads(reader3):
ops = 0
read = 0
Expand All @@ -379,7 +365,6 @@ async def test_small_reads(reader3):


@pytest.mark.slow
@falcon.runs_sync
async def test_small_reads_with_delimiter(reader3):
ops = 0
read = 0
Expand Down
3 changes: 0 additions & 3 deletions tests/asgi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@
from falcon.http_status import HTTPStatus


@pytest.mark.asyncio
async def test_http_status_not_impl():
app = App()
with pytest.raises(NotImplementedError):
await app._http_status_handler(MagicMock(), None, HTTPStatus(200), {}, None)


@pytest.mark.asyncio
async def test_http_error_not_impl():
app = App()
with pytest.raises(NotImplementedError):
await app._http_error_handler(MagicMock(), None, HTTPError(400), {}, None)


@pytest.mark.asyncio
async def test_python_error_not_impl():
app = App()
with pytest.raises(NotImplementedError):
Expand Down
1 change: 0 additions & 1 deletion tests/asgi/test_request_body_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_tiny_body_overflow(self, client, resource):
(8192, 50),
],
)
@pytest.mark.asyncio
async def test_content_length_smaller_than_body(self, body_length, content_length):
body_in = os.urandom(body_length)

Expand Down
2 changes: 0 additions & 2 deletions tests/asgi/test_scheduled_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest

from falcon import runs_sync
from falcon import testing
from falcon.asgi import App

Expand Down Expand Up @@ -138,7 +137,6 @@ def callback_app(simple_resource):
('GET', '/stream', 'One\nTwo\nThree\n'),
],
)
@runs_sync
async def test_callback(callback_app, simple_resource, method, uri, expected):
async with testing.ASGIConductor(callback_app) as conductor:
resp = await conductor.simulate_request(method, uri)
Expand Down
1 change: 0 additions & 1 deletion tests/asgi/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def callme_shirley(a=42, b=None):
assert val[1] is None or (0 <= val[1] < 1000)


@pytest.mark.asyncio
async def test_sync_asyncio_aliases():
async def dummy_async_func():
pass
Expand Down
Loading

0 comments on commit a65d807

Please sign in to comment.