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

During tests: the on_startup signal is sent before the loop is set #2060

Closed
cecton opened this issue Jul 6, 2017 · 3 comments
Closed

During tests: the on_startup signal is sent before the loop is set #2060

cecton opened this issue Jul 6, 2017 · 3 comments
Labels

Comments

@cecton
Copy link
Contributor

cecton commented Jul 6, 2017

Long story short

Between the version 2.1 and 2.2 we change the order of when the signal on_startup is sent during the tests and when we make the handlers. Because of that, all the on_startup hooks doesn't have a loop in app.loop.

ed28add

commit ed28add756e2a5dc8caf082641ac1d1810a18c7a
Author: Andrew Svetlov <[email protected]>
Date:   Thu Jun 15 00:51:40 2017 +0300

    Fix #1947: don't raise DeprecationWarning inside on_startup() handler for test_utils

diff --git a/CHANGES.rst b/CHANGES.rst
index 82e545b9..d1640a92 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,7 +18,8 @@ Changes
 
 - Use CIMultiDict for ClientRequest.skip_auto_headers #1970
 
--
+- Fix wrong startup sequence: test server doesn't raise
+  `DeprecationWarning` now #1947
 
 -
 
diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py
index 4791cde8..21f89362 100644
--- a/aiohttp/test_utils.py
+++ b/aiohttp/test_utils.py
@@ -148,8 +148,8 @@ class TestServer(BaseTestServer):
 
     @asyncio.coroutine
     def _make_factory(self, **kwargs):
-        self.handler = self.app.make_handler(loop=self._loop, **kwargs)
         yield from self.app.startup()
+        self.handler = self.app.make_handler(loop=self._loop, **kwargs)
         return self.handler
 
     @asyncio.coroutine

Expected behaviour

Keep the behavior consistent when running the app within or without a test.

Actual behaviour

app.loop is None during a test but it is an event loop when running with web.run_app.

Steps to reproduce

import aiohttp
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop
from distutils.version import StrictVersion


async def hook(app):
    assert StrictVersion(aiohttp.__version__) >= StrictVersion("2.2")
    assert app.loop is not None # fails in the test case but not in run_app


class TestCase(AioHTTPTestCase):
    async def get_application(self):
        app = web.Application()
        app.on_startup.append(hook)
        return app

    @unittest_run_loop
    async def test_on_startup_hook(self):
        pass # will fail before executing the test


if __name__ == '__main__':
    app = web.Application()
    app.on_startup.append(hook)
    web.run_app(app)

Your environment

ArchLinux, Python 3.6

@cecton
Copy link
Contributor Author

cecton commented Jul 7, 2017

Linked to #1947 and #1964

cecton added a commit to cecton/aiohttp that referenced this issue Jul 7, 2017
cecton added a commit to cecton/aiohttp that referenced this issue Jul 7, 2017
cecton added a commit to cecton/aiohttp that referenced this issue Jul 7, 2017
@cecton cecton changed the title During tests: the on_startup signal is sent before the loop is set during During tests: the on_startup signal is sent before the loop is set Jul 8, 2017
@cecton
Copy link
Contributor Author

cecton commented Jul 10, 2017

Fixed by #2068

@cecton cecton closed this as completed Jul 10, 2017
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant