Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import asyncio

import pytest

pytest.register_assert_rewrite("webargs.testing")


@pytest.fixture
def current_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
asyncio.set_event_loop(None)
loop.close()
2 changes: 2 additions & 0 deletions tests/test_falconparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ def test_body_parsing_works_with_simulate(self):
)
assert res.json == {"name": "Fred"}

@pytest.mark.usefixtures("current_loop")
def test_parse_querystring_args_async(self):
app = create_async_app()
client = falcon.testing.TestClient(app)
assert client.simulate_get("/async_echo?name=Fred").json == {"name": "Fred"}

@pytest.mark.usefixtures("current_loop")
def test_async_use_args_decorator(self):
app = create_async_app()
client = falcon.testing.TestClient(app)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_tornadoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ def test_it_should_not_include_fieldnames_if_not_present(self):
result = parser.load_json(request, author_schema)
assert result == {}

@pytest.mark.usefixtures("current_loop")
def test_it_should_handle_type_error_on_load_json(self):
# but this is different from the test above where the payload was valid
# and empty -- missing vs {}
# NOTE: `event_loop` is the pytest-aiohttp event loop fixture, but it's
# important to get an event loop here so that we can construct a future
# NOTE: the `current_loop` fixture sets a current event loop,
# which is required here so that we can construct a future
request = make_request(
body=tornado.concurrent.Future(),
headers={"Content-Type": "application/json"},
Expand Down