@@ -165,8 +165,36 @@ def _configurable_serverapp(
165
165
return _configurable_serverapp
166
166
167
167
168
+ @pytest .fixture
169
+ def jp_ensure_app_fixture (request ):
170
+ """Ensures that the 'app' fixture used by pytest-tornasync
171
+ is set to `jp_web_app`, the Tornado Web Application returned
172
+ by the ServerApp in Jupyter Server, provided by the jp_web_app
173
+ fixture in this module.
174
+
175
+ Note, this hardcodes the `app_fixture` option from
176
+ pytest-tornasync to `jp_web_app`. If this value is configured
177
+ to something other than the default, it will raise an exception.
178
+ """
179
+ app_option = request .config .getoption ("app_fixture" )
180
+ if app_option not in ["app" , "jp_web_app" ]:
181
+ raise Exception ("jp_serverapp requires the `app-fixture` option "
182
+ "to be set to 'jp_web_app`. Try rerunning the "
183
+ "current tests with the option `--app-fixture "
184
+ "jp_web_app`." )
185
+ elif app_option == "app" :
186
+ # Manually set the app_fixture to `jp_web_app` if it's
187
+ # not set already.
188
+ request .config .option .app_fixture = "jp_web_app"
189
+
190
+
168
191
@pytest .fixture (scope = "function" )
169
- def jp_serverapp (jp_server_config , jp_argv , jp_configurable_serverapp ):
192
+ def jp_serverapp (
193
+ jp_ensure_app_fixture ,
194
+ jp_server_config ,
195
+ jp_argv ,
196
+ jp_configurable_serverapp
197
+ ):
170
198
"""Starts a Jupyter Server instance based on the established configuration values."""
171
199
app = jp_configurable_serverapp (config = jp_server_config , argv = jp_argv )
172
200
yield app
@@ -176,7 +204,7 @@ def jp_serverapp(jp_server_config, jp_argv, jp_configurable_serverapp):
176
204
177
205
178
206
@pytest .fixture
179
- def app (jp_serverapp ):
207
+ def jp_web_app (jp_serverapp ):
180
208
"""app fixture is needed by pytest_tornasync plugin"""
181
209
return jp_serverapp .web_app
182
210
@@ -194,7 +222,7 @@ def jp_base_url():
194
222
195
223
196
224
@pytest .fixture
197
- def jp_fetch (http_server_client , jp_auth_header , jp_base_url ):
225
+ def jp_fetch (jp_serverapp , http_server_client , jp_auth_header , jp_base_url ):
198
226
"""Sends an (asynchronous) HTTP request to a test server.
199
227
200
228
The fixture is a factory; it can be called like
@@ -223,7 +251,7 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
223
251
224
252
225
253
@pytest .fixture
226
- def jp_ws_fetch (jp_auth_header , jp_http_port ):
254
+ def jp_ws_fetch (jp_serverapp , jp_auth_header , jp_http_port ):
227
255
"""Sends a websocket request to a test server.
228
256
229
257
The fixture is a factory; it can be called like
0 commit comments