Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp request and response normalization #205

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sportsracer
Copy link

Support validating aiohttp requests and responses!

CI and linter are green. Also updated the docs.

The test cases mock requests and responses, rather than make actual requests, since it's not trivial to get async code running in the test suite.

Looking forward to your feedback.

def test_aiohttp_request_normalization():
from aiohttp.test_utils import make_mocked_request

raw_request = make_mocked_request(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this since it is from the formal aiohttp tools, however, it is pretty easy to do async testing with pytest.

@pytest.mark.asyncio
async def my_async_test():
    response = await ....

Since we have the httpbin fixture which runs a local webserver it should be pretty easy to generate a real request/response.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. I would also have to use the compatibility utils from asyncio to not get a syntax error in Python < 3.5.

I may try this if I find the time, since the aiohttp.test_utils API is marked as provisional, which may break this test in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is tricky, since the tests need to pass for Python 2.

An async keyword just triggers a syntax error, with no chance for pytest to even skip the test. Even if I use the Python <3.5 @asyncio.coroutine syntax, I get a syntax error due to the yield from statement.

It looks to me like the only way to get actual async tests to run for newer versions is to move them to their own file, and ignore them during test collection, e.g. like this: pytest-dev/pytest#2817 (which may have further side effects; after all, we don't want to skip any other test files on syntax errors).

@pipermerriam does this still seem worth exploring to you?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New maintainer here. Yes, please explore that!

@blag
Copy link
Collaborator

blag commented May 10, 2019

At this point, with Python 2 being officially unsupported in less than a year, if you or somebody else wants to rewrite this to require Python 3.6+, I would accept that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants