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

AioHTTPTestCase more async friendly #4732

Merged
merged 13 commits into from
Nov 18, 2020

Conversation

WisdomPill
Copy link
Member

@WisdomPill WisdomPill commented May 9, 2020

What do these changes do?

Make AioHTTPTestCase more async friendly, making a user able to run a test case with async methods without needing to use @unittest_run_loop decorator, adding a dependency for testing for python3.7 and below as mentioned in #4700 and #4695 while using built in asyncio test case available from python 3.8

This change is backward compatible, I did not change any name of classes or methods.

Are there changes in behavior for the user?

Yes, test can be written with async functions without @unittest_run_loop.
For python3.7 and below asynctest dependency must be installed.

Testing becomes more straight forward like the following

from aiohttp.test_utils import AioHTTPTestCase
from aiohttp.web_app import Application
from aiohttp.web_request import Request
from aiohttp.web_response import Response
from aiohttp.web_routedef import get

async def ping(request: Request) -> Response:
    return Response(text='pong')


class TestApplication(AioHTTPTestCase):
    def get_app(self) -> Application:
        app = Application()
        app.router.add_routes([
            get('/ping/', ping)
        ])

        return app

    async def test_ping(self):
        resp = await self.client.get('/ping/')

        self.assertEqual(resp.status, 200)
        self.assertEqual(await resp.text(), 'pong')

Related issue number

#4700 and #4695

#4700 will be resolved after this merge

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

I did not add any new tests, it seems to me that the old tests are passing, I would be glad to know if this kind of change is welcome so that I can proceed with the docs and more testing maybe on the patching side like I pointed out in this PR #4697

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 9, 2020
@codecov-io
Copy link

codecov-io commented May 9, 2020

Codecov Report

Merging #4732 (838cf36) into master (37d2376) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4732   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files          43       43           
  Lines        8794     8794           
  Branches     1413     1415    +2     
=======================================
  Hits         8578     8578           
  Misses        101      101           
  Partials      115      115           
Flag Coverage Δ
unit 97.37% <84.61%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/test_utils.py 99.68% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37d2376...838cf36. Read the comment docs.

@WisdomPill
Copy link
Member Author

I've added tests to prove the new capabilities of AioHTTPTestCase,

Maybe the next step would be to add patch tests?

Should @unittest_run_loop be deprecated now?

CHANGES/4700.feature Outdated Show resolved Hide resolved
CHANGES/4700.feature Outdated Show resolved Hide resolved
@CLAassistant

This comment has been minimized.

@WisdomPill
Copy link
Member Author

@asvetlov how can I solve the CLA that is not signed?

@asvetlov
Copy link
Member

Please forget about the CLA.
We had a discussion, many people don't like it and I was convinced that the CLA is not required actually.
Switched it off back.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Interesting, I thought that the difference between asynctest and IsolatedAsyncioTestCase is bigger.

CHANGES/4700.feature Outdated Show resolved Hide resolved
CHANGES/4700.feature Outdated Show resolved Hide resolved
requirements/dev.txt Outdated Show resolved Hide resolved
Co-authored-by: Andrew Svetlov <[email protected]>
WisdomPill and others added 2 commits November 18, 2020 22:14
Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
@asvetlov asvetlov merged commit 5357858 into aio-libs:master Nov 18, 2020
@aio-libs-github-bot
Copy link
Contributor

💔 Backport was not successful

The PR was attempted backported to the following branches:

  • ❌ 3.8: Commit could not be cherrypicked due to conflicts

asvetlov pushed a commit that referenced this pull request Nov 18, 2020
Co-authored-by: Andrew Svetlov <[email protected]>.
(cherry picked from commit 5357858)

Co-authored-by: Anas <[email protected]>
asvetlov added a commit that referenced this pull request Nov 18, 2020
Co-authored-by: Andrew Svetlov <[email protected]>.
(cherry picked from commit 5357858)

Co-authored-by: Anas <[email protected]>

Co-authored-by: Anas <[email protected]>
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
H--o-l added a commit to H--o-l/aiohttp that referenced this pull request Nov 15, 2021
Since aio-libs#4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.
H--o-l added a commit to H--o-l/aiohttp that referenced this pull request Nov 16, 2021
Since aio-libs#4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.
H--o-l added a commit to H--o-l/aiohttp that referenced this pull request Nov 16, 2021
Since aio-libs#4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.
H--o-l added a commit to H--o-l/aiohttp that referenced this pull request Nov 16, 2021
Since aio-libs#4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.
asvetlov pushed a commit that referenced this pull request Nov 16, 2021
Since #4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.
patchback bot pushed a commit that referenced this pull request Nov 16, 2021
Since #4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.

(cherry picked from commit d149eff)
patchback bot pushed a commit that referenced this pull request Nov 16, 2021
Since #4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.

(cherry picked from commit d149eff)
asvetlov pushed a commit that referenced this pull request Nov 16, 2021
#6318)

Since #4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.

(cherry picked from commit d149eff)

Co-authored-by: Hoel IRIS <[email protected]>
asvetlov pushed a commit that referenced this pull request Nov 16, 2021
#6317)

Since #4732, it's wrong to says that
`setUpAsync()` and `tearDownAsync()` do nothing and can be overridden without
calling `super.setUpAsync()` and `super.tearDownAsync()`.

(cherry picked from commit d149eff)

Co-authored-by: Hoel IRIS <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants