|
7 | 7 | from aiohttp import ClientTimeout
|
8 | 8 | from pytest_toolbox import mktree
|
9 | 9 |
|
| 10 | +from multiprocessing import set_start_method |
| 11 | + |
10 | 12 | from aiohttp_devtools.runserver import runserver
|
11 | 13 | from aiohttp_devtools.runserver.config import Config
|
12 | 14 | from aiohttp_devtools.runserver.serve import (
|
13 | 15 | WS, create_auxiliary_app, create_main_app, modify_main_app, src_reload, start_main_app)
|
| 16 | +from aiohttp_devtools.runserver.watch import AppTask |
14 | 17 |
|
15 | 18 | from .conftest import SIMPLE_APP, forked
|
16 | 19 |
|
@@ -112,6 +115,42 @@ async def hello(request):
|
112 | 115 | assert len(aux_app.cleanup_ctx) == 1
|
113 | 116 |
|
114 | 117 |
|
| 118 | +@forked |
| 119 | +def test_start_runserver_with_multi_app_modules(tmpworkdir, event_loop, capfd): |
| 120 | + mktree(tmpworkdir, { |
| 121 | + "app.py": f"""\ |
| 122 | +from aiohttp import web |
| 123 | +import sys |
| 124 | +sys.path.insert(0, "{tmpworkdir}/libs/l1") |
| 125 | +
|
| 126 | +async def hello(request): |
| 127 | + return web.Response(text="<h1>hello world</h1>", content_type="text/html") |
| 128 | +
|
| 129 | +async def create_app(): |
| 130 | + a = web.Application() |
| 131 | + a.router.add_get("/", hello) |
| 132 | + return a |
| 133 | +""", |
| 134 | + "libs": { |
| 135 | + "l1": { |
| 136 | + "__init__.py": "", |
| 137 | + "app.py": "print('wrong_import')" |
| 138 | + } |
| 139 | + } |
| 140 | + }) |
| 141 | + |
| 142 | + set_start_method("spawn") |
| 143 | + config = Config(app_path="app.py", root_path=tmpworkdir, main_port=0, app_factory_name="create_app") |
| 144 | + config.import_app_factory() |
| 145 | + app_task = AppTask(config) |
| 146 | + |
| 147 | + app_task._start_dev_server() |
| 148 | + app_task._process.join(2) |
| 149 | + |
| 150 | + captured = capfd.readouterr() |
| 151 | + assert captured.out == "" |
| 152 | + |
| 153 | + |
115 | 154 | @forked
|
116 | 155 | async def test_run_app_aiohttp_client(tmpworkdir, aiohttp_client):
|
117 | 156 | mktree(tmpworkdir, SIMPLE_APP)
|
|
0 commit comments