|
1 | 1 | # Copyright (c) Jupyter Development Team. |
2 | 2 | # Distributed under the terms of the Modified BSD License. |
3 | 3 |
|
4 | | -import asyncio |
5 | 4 | import importlib |
6 | 5 | import io |
7 | 6 | import logging |
|
45 | 44 | ) |
46 | 45 |
|
47 | 46 |
|
| 47 | +# Bring in core plugins. |
| 48 | +from pytest_jupyter import * # noqa |
48 | 49 | from pytest_jupyter.utils import mkdir |
49 | 50 |
|
50 | 51 | # List of dependencies needed for this plugin. |
51 | | -pytest_plugins = ["pytest_tornasync", "pytest_jupyter.jupyter_client"] |
| 52 | +pytest_plugins = ["pytest_tornasync"] |
52 | 53 |
|
53 | 54 |
|
54 | | -@pytest.fixture |
55 | | -def asyncio_loop(): |
56 | | - loop = asyncio.new_event_loop() |
57 | | - asyncio.set_event_loop(loop) |
58 | | - yield loop |
59 | | - loop.close() |
60 | | - |
61 | | - |
62 | | -@pytest.fixture(autouse=True) |
63 | | -def io_loop(asyncio_loop): |
64 | | - async def get_tornado_loop(): |
65 | | - return tornado.ioloop.IOLoop.current() |
66 | | - |
67 | | - return asyncio_loop.run_until_complete(get_tornado_loop()) |
| 55 | +# Override some of the fixtures from pytest_tornasync |
| 56 | +# The io_loop fixture is overidden in jupyter_core.py so it |
| 57 | +# can be shared by other plugins that need it (e.g. jupyter_client.py). |
68 | 58 |
|
69 | 59 |
|
70 | 60 | @pytest.fixture |
@@ -100,6 +90,9 @@ async def get_server(): |
100 | 90 | http_server_port[0].close() |
101 | 91 |
|
102 | 92 |
|
| 93 | +# End pytest_tornasync overrides |
| 94 | + |
| 95 | + |
103 | 96 | @pytest.fixture |
104 | 97 | def jp_server_config(): |
105 | 98 | """Allows tests to setup their specific configuration values.""" |
@@ -132,19 +125,19 @@ def jp_argv(): |
132 | 125 | return [] |
133 | 126 |
|
134 | 127 |
|
135 | | -@pytest.fixture |
136 | | -def jp_extension_environ(jp_env_config_path, monkeypatch): |
137 | | - """Monkeypatch a Jupyter Extension's config path into each test's environment variable""" |
138 | | - monkeypatch.setattr(serverextension, "ENV_CONFIG_PATH", [str(jp_env_config_path)]) |
139 | | - |
140 | | - |
141 | | -@pytest.fixture |
| 128 | +@pytest.fixture() |
142 | 129 | def jp_http_port(http_server_port): |
143 | 130 | """Returns the port value from the http_server_port fixture.""" |
144 | 131 | yield http_server_port[-1] |
145 | 132 | http_server_port[0].close() |
146 | 133 |
|
147 | 134 |
|
| 135 | +@pytest.fixture |
| 136 | +def jp_extension_environ(jp_env_config_path, monkeypatch): |
| 137 | + """Monkeypatch a Jupyter Extension's config path into each test's environment variable""" |
| 138 | + monkeypatch.setattr(serverextension, "ENV_CONFIG_PATH", [str(jp_env_config_path)]) |
| 139 | + |
| 140 | + |
148 | 141 | @pytest.fixture |
149 | 142 | def jp_nbconvert_templates(jp_data_dir): |
150 | 143 | """Setups up a temporary directory consisting of the nbconvert templates.""" |
@@ -192,9 +185,8 @@ def jp_configurable_serverapp( |
192 | 185 | tmp_path, |
193 | 186 | jp_root_dir, |
194 | 187 | jp_logging_stream, |
195 | | - asyncio_loop, |
| 188 | + jp_asyncio_loop, |
196 | 189 | io_loop, |
197 | | - echo_kernel_spec, # noqa |
198 | 190 | ): |
199 | 191 | """Starts a Jupyter Server instance based on |
200 | 192 | the provided configuration values. |
@@ -261,14 +253,14 @@ def _configurable_serverapp( |
261 | 253 | app.log.propagate = True |
262 | 254 | app.log.handlers = [] |
263 | 255 | # Initialize app without httpserver |
264 | | - if asyncio_loop.is_running(): |
| 256 | + if jp_asyncio_loop.is_running(): |
265 | 257 | app.initialize(argv=argv, new_httpserver=False) |
266 | 258 | else: |
267 | 259 |
|
268 | 260 | async def initialize_app(): |
269 | 261 | app.initialize(argv=argv, new_httpserver=False) |
270 | 262 |
|
271 | | - asyncio_loop.run_until_complete(initialize_app()) |
| 263 | + jp_asyncio_loop.run_until_complete(initialize_app()) |
272 | 264 | # Reroute all logging StreamHandlers away from stdin/stdout since pytest hijacks |
273 | 265 | # these streams and closes them at unfortunate times. |
274 | 266 | stream_handlers = [h for h in app.log.handlers if isinstance(h, logging.StreamHandler)] |
@@ -410,11 +402,11 @@ def inner(nbpath): |
410 | 402 |
|
411 | 403 |
|
412 | 404 | @pytest.fixture(autouse=True) |
413 | | -def jp_server_cleanup(asyncio_loop): |
| 405 | +def jp_server_cleanup(jp_asyncio_loop): |
414 | 406 | yield |
415 | 407 | app: ServerApp = ServerApp.instance() |
416 | 408 | try: |
417 | | - asyncio_loop.run_until_complete(app._cleanup()) |
| 409 | + jp_asyncio_loop.run_until_complete(app._cleanup()) |
418 | 410 | except (RuntimeError, SystemExit) as e: |
419 | 411 | print("ignoring cleanup error", e) |
420 | 412 | if hasattr(app, "kernel_manager"): |
|
0 commit comments