Skip to content

Commit

Permalink
restore pytest settings and remove usages of jp_cleanup_subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Apr 26, 2022
1 parent 68c4b7e commit a48e2f5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 112 deletions.
2 changes: 1 addition & 1 deletion jupyter_server/pytest_plugin.py
Expand Up @@ -482,7 +482,7 @@ def jp_server_cleanup(io_loop):

@pytest.fixture
def jp_cleanup_subprocesses(jp_serverapp):
"""Clean up subprocesses started by a Jupyter Server, i.e. kernels and terminal."""
"""DEPRECATED: The jp_server_cleanup fixture automatically cleans up the singleton ServerApp class"""

async def _():
pass
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -13,9 +13,9 @@ addopts = "-raXs --durations 10 --color=yes --doctest-modules"
testpaths = [
"tests/"
]
timeout = 30
timeout = 300
# Restore this setting to debug failures
timeout_method = "thread"
# timeout_method = "thread"
filterwarnings = [
"error",
"ignore:There is no current event loop:DeprecationWarning",
Expand Down
3 changes: 0 additions & 3 deletions tests/auth/test_authorizer.py
Expand Up @@ -205,7 +205,6 @@ async def test_authorized_requests(
send_request,
tmp_path,
jp_serverapp,
jp_cleanup_subprocesses,
method,
url,
body,
Expand Down Expand Up @@ -275,5 +274,3 @@ async def test_authorized_requests(

code = await send_request(url, body=body, method=method)
assert code in expected_codes

await jp_cleanup_subprocesses()
22 changes: 6 additions & 16 deletions tests/services/kernels/test_api.py
Expand Up @@ -67,7 +67,7 @@ async def test_no_kernels(jp_fetch):


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_default_kernels(jp_fetch, jp_base_url, jp_cleanup_subprocesses):
async def test_default_kernels(jp_fetch, jp_base_url):
r = await jp_fetch("api", "kernels", method="POST", allow_nonstandard_methods=True)
kernel = json.loads(r.body.decode())
assert r.headers["location"] == url_path_join(jp_base_url, "/api/kernels/", kernel["id"])
Expand All @@ -79,13 +79,10 @@ async def test_default_kernels(jp_fetch, jp_base_url, jp_cleanup_subprocesses):
["frame-ancestors 'self'", "report-uri " + report_uri, "default-src 'none'"]
)
assert r.headers["Content-Security-Policy"] == expected_csp
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_main_kernel_handler(
jp_fetch, jp_base_url, jp_cleanup_subprocesses, jp_serverapp, pending_kernel_is_ready
):
async def test_main_kernel_handler(jp_fetch, jp_base_url, jp_serverapp, pending_kernel_is_ready):
# Start the first kernel
r = await jp_fetch(
"api", "kernels", method="POST", body=json.dumps({"name": NATIVE_KERNEL_NAME})
Expand Down Expand Up @@ -158,11 +155,10 @@ async def test_main_kernel_handler(
)
kernel3 = json.loads(r.body.decode())
assert isinstance(kernel3, dict)
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_kernel_handler(jp_fetch, jp_cleanup_subprocesses, pending_kernel_is_ready):
async def test_kernel_handler(jp_fetch, pending_kernel_is_ready):
# Create a kernel
r = await jp_fetch(
"api", "kernels", method="POST", body=json.dumps({"name": NATIVE_KERNEL_NAME})
Expand Down Expand Up @@ -206,13 +202,10 @@ async def test_kernel_handler(jp_fetch, jp_cleanup_subprocesses, pending_kernel_
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
await jp_fetch("api", "kernels", bad_id, method="DELETE")
assert expected_http_error(e, 404, "Kernel does not exist: " + bad_id)
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_kernel_handler_startup_error(
jp_fetch, jp_cleanup_subprocesses, jp_serverapp, jp_kernelspecs
):
async def test_kernel_handler_startup_error(jp_fetch, jp_serverapp, jp_kernelspecs):
if getattr(jp_serverapp.kernel_manager, "use_pending_kernels", False):
return

Expand All @@ -223,7 +216,7 @@ async def test_kernel_handler_startup_error(

@pytest.mark.timeout(TEST_TIMEOUT)
async def test_kernel_handler_startup_error_pending(
jp_fetch, jp_ws_fetch, jp_cleanup_subprocesses, jp_serverapp, jp_kernelspecs
jp_fetch, jp_ws_fetch, jp_serverapp, jp_kernelspecs
):
if not getattr(jp_serverapp.kernel_manager, "use_pending_kernels", False):
return
Expand All @@ -238,9 +231,7 @@ async def test_kernel_handler_startup_error_pending(


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_connection(
jp_fetch, jp_ws_fetch, jp_http_port, jp_auth_header, jp_cleanup_subprocesses
):
async def test_connection(jp_fetch, jp_ws_fetch, jp_http_port, jp_auth_header):
# Create kernel
r = await jp_fetch(
"api", "kernels", method="POST", body=json.dumps({"name": NATIVE_KERNEL_NAME})
Expand Down Expand Up @@ -274,4 +265,3 @@ async def test_connection(
r = await jp_fetch("api", "kernels", kid, method="GET")
model = json.loads(r.body.decode())
assert model["connections"] == 0
await jp_cleanup_subprocesses()
8 changes: 2 additions & 6 deletions tests/services/kernels/test_cull.py
Expand Up @@ -43,7 +43,7 @@
),
],
)
async def test_cull_idle(jp_fetch, jp_ws_fetch, jp_cleanup_subprocesses):
async def test_cull_idle(jp_fetch, jp_ws_fetch):
r = await jp_fetch("api", "kernels", method="POST", allow_nonstandard_methods=True)
kernel = json.loads(r.body.decode())
kid = kernel["id"]
Expand All @@ -59,7 +59,6 @@ async def test_cull_idle(jp_fetch, jp_ws_fetch, jp_cleanup_subprocesses):
ws.close()
culled = await get_cull_status(kid, jp_fetch) # not connected, should be culled
assert culled
await jp_cleanup_subprocesses()


# Pending kernels was released in Jupyter Client 7.1
Expand Down Expand Up @@ -89,9 +88,7 @@ async def test_cull_idle(jp_fetch, jp_ws_fetch, jp_cleanup_subprocesses):
],
)
@pytest.mark.timeout(30)
async def test_cull_dead(
jp_fetch, jp_ws_fetch, jp_serverapp, jp_cleanup_subprocesses, jp_kernelspecs
):
async def test_cull_dead(jp_fetch, jp_ws_fetch, jp_serverapp, jp_kernelspecs):
r = await jp_fetch("api", "kernels", method="POST", allow_nonstandard_methods=True)
kernel = json.loads(r.body.decode())
kid = kernel["id"]
Expand All @@ -105,7 +102,6 @@ async def test_cull_dead(
assert model["connections"] == 0
culled = await get_cull_status(kid, jp_fetch) # connected, should not be culled
assert culled
await jp_cleanup_subprocesses()


async def get_cull_status(kid, jp_fetch):
Expand Down
82 changes: 14 additions & 68 deletions tests/services/sessions/test_api.py
Expand Up @@ -211,7 +211,7 @@ def assert_session_equality(actual, expected):


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create(session_client, jp_base_url, jp_cleanup_subprocesses, jp_serverapp):
async def test_create(session_client, jp_base_url, jp_serverapp):
# Make sure no sessions exist.
resp = await session_client.list()
sessions = j(resp)
Expand Down Expand Up @@ -251,14 +251,9 @@ async def test_create(session_client, jp_base_url, jp_cleanup_subprocesses, jp_s
got = j(resp)
assert_session_equality(got, new_session)

# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_bad(
session_client, jp_base_url, jp_cleanup_subprocesses, jp_serverapp, jp_kernelspecs
):
async def test_create_bad(session_client, jp_base_url, jp_serverapp, jp_kernelspecs):
if getattr(jp_serverapp.kernel_manager, "use_pending_kernels", False):
return

Expand All @@ -272,16 +267,12 @@ async def test_create_bad(
with pytest.raises(HTTPClientError):
await session_client.create("foo/nb1.ipynb")

# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_bad_pending(
session_client,
jp_base_url,
jp_ws_fetch,
jp_cleanup_subprocesses,
jp_serverapp,
jp_kernelspecs,
):
Expand Down Expand Up @@ -310,56 +301,41 @@ async def test_create_bad_pending(
if os.name != "nt":
assert "non_existent_path" in session["kernel"]["reason"]

# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_file_session(
session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_create_file_session(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.py", type="file")
assert resp.code == 201
newsession = j(resp)
assert newsession["path"] == "foo/nb1.py"
assert newsession["type"] == "file"
sid = newsession["id"]
await session_is_ready(sid)
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_console_session(
session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_create_console_session(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/abc123", type="console")
assert resp.code == 201
newsession = j(resp)
assert newsession["path"] == "foo/abc123"
assert newsession["type"] == "console"
# Need to find a better solution to this.
sid = newsession["id"]
await session_is_ready(sid)
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_deprecated(session_client, jp_cleanup_subprocesses, jp_serverapp):
async def test_create_deprecated(session_client, jp_serverapp):
resp = await session_client.create_deprecated("foo/nb1.ipynb")
assert resp.code == 201
newsession = j(resp)
assert newsession["path"] == "foo/nb1.ipynb"
assert newsession["type"] == "notebook"
assert newsession["notebook"]["path"] == "foo/nb1.ipynb"
# Need to find a better solution to this.
sid = newsession["id"]
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_with_kernel_id(
session_client, jp_fetch, jp_base_url, jp_cleanup_subprocesses, jp_serverapp
):
async def test_create_with_kernel_id(session_client, jp_fetch, jp_base_url, jp_serverapp):
# create a new kernel
resp = await jp_fetch("api/kernels", method="POST", allow_nonstandard_methods=True)
kernel = j(resp)
Expand All @@ -384,14 +360,10 @@ async def test_create_with_kernel_id(
resp = await session_client.get(sid)
got = j(resp)
assert_session_equality(got, new_session)
# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_create_with_bad_kernel_id(
session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_create_with_bad_kernel_id(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.py", type="file")
assert resp.code == 201
newsession = j(resp)
Expand All @@ -401,11 +373,10 @@ async def test_create_with_bad_kernel_id(
# TODO
assert newsession["path"] == "foo/nb1.py"
assert newsession["type"] == "file"
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_delete(session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready):
async def test_delete(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")

newsession = j(resp)
Expand All @@ -422,12 +393,10 @@ async def test_delete(session_client, jp_cleanup_subprocesses, jp_serverapp, ses
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
await session_client.get(sid)
assert expected_http_error(e, 404)
# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_modify_path(session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready):
async def test_modify_path(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")
newsession = j(resp)
sid = newsession["id"]
Expand All @@ -437,14 +406,10 @@ async def test_modify_path(session_client, jp_cleanup_subprocesses, jp_serverapp
changed = j(resp)
assert changed["id"] == sid
assert changed["path"] == "nb2.ipynb"
# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_modify_path_deprecated(
session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_modify_path_deprecated(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")
newsession = j(resp)
sid = newsession["id"]
Expand All @@ -454,12 +419,10 @@ async def test_modify_path_deprecated(
changed = j(resp)
assert changed["id"] == sid
assert changed["notebook"]["path"] == "nb2.ipynb"
# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_modify_type(session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready):
async def test_modify_type(session_client, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")
newsession = j(resp)
sid = newsession["id"]
Expand All @@ -469,14 +432,10 @@ async def test_modify_type(session_client, jp_cleanup_subprocesses, jp_serverapp
changed = j(resp)
assert changed["id"] == sid
assert changed["type"] == "console"
# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_modify_kernel_name(
session_client, jp_fetch, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_modify_kernel_name(session_client, jp_fetch, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")
before = j(resp)
sid = before["id"]
Expand All @@ -497,14 +456,9 @@ async def test_modify_kernel_name(
if not getattr(jp_serverapp.kernel_manager, "use_pending_kernels", False):
assert kernel_list == [after["kernel"]]

# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_modify_kernel_id(
session_client, jp_fetch, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
async def test_modify_kernel_id(session_client, jp_fetch, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")
before = j(resp)
sid = before["id"]
Expand Down Expand Up @@ -532,14 +486,9 @@ async def test_modify_kernel_id(
if not getattr(jp_serverapp.kernel_manager, "use_pending_kernels", False):
assert kernel_list == [kernel]

# Need to find a better solution to this.
await jp_cleanup_subprocesses()


@pytest.mark.timeout(TEST_TIMEOUT)
async def test_restart_kernel(
session_client, jp_base_url, jp_fetch, jp_ws_fetch, jp_cleanup_subprocesses, session_is_ready
):
async def test_restart_kernel(session_client, jp_base_url, jp_fetch, jp_ws_fetch, session_is_ready):
# Create a session.
resp = await session_client.create("foo/nb1.ipynb")
assert resp.code == 201
Expand Down Expand Up @@ -596,6 +545,3 @@ async def test_restart_kernel(
r = await jp_fetch("api", "kernels", kid, method="GET")
model = json.loads(r.body.decode())
assert model["connections"] == 1

# Need to find a better solution to this.
await jp_cleanup_subprocesses()

0 comments on commit a48e2f5

Please sign in to comment.