Skip to content

Commit d80e4f6

Browse files
authored
Merge pull request #6 from kevin-bates/jp_web_app
Replace app fixture with jp_web_app to avoid conflicts
2 parents fe60208 + aada357 commit d80e4f6

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

pytest_jupyter/jupyter_server.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,36 @@ def _configurable_serverapp(
165165
return _configurable_serverapp
166166

167167

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+
168191
@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+
):
170198
"""Starts a Jupyter Server instance based on the established configuration values."""
171199
app = jp_configurable_serverapp(config=jp_server_config, argv=jp_argv)
172200
yield app
@@ -176,7 +204,7 @@ def jp_serverapp(jp_server_config, jp_argv, jp_configurable_serverapp):
176204

177205

178206
@pytest.fixture
179-
def app(jp_serverapp):
207+
def jp_web_app(jp_serverapp):
180208
"""app fixture is needed by pytest_tornasync plugin"""
181209
return jp_serverapp.web_app
182210

@@ -194,7 +222,7 @@ def jp_base_url():
194222

195223

196224
@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):
198226
"""Sends an (asynchronous) HTTP request to a test server.
199227
200228
The fixture is a factory; it can be called like
@@ -223,7 +251,7 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
223251

224252

225253
@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):
227255
"""Sends a websocket request to a test server.
228256
229257
The fixture is a factory; it can be called like

0 commit comments

Comments
 (0)