From ddfd913f91b780a308a8d2d985ce0fa844d40b8b Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 27 Nov 2023 15:04:55 +0100 Subject: [PATCH] Update testing for JupyterHub 4 --- dev-requirements.txt | 7 ++-- pytest.ini | 1 + tljh-plasma/tljh_plasma/tests/conftest.py | 51 +++++------------------ 3 files changed, 15 insertions(+), 44 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 9a2e485..d595d4a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,9 +1,10 @@ git+https://github.com/jupyterhub/the-littlest-jupyterhub@1.0.0 -git+https://github.com/plasmabio/tljh-repo2docker -jupyterhub~=1.5 -notebook<7 +git+https://github.com/jtpio/tljh-repo2docker@jupyterhub-4 +jupyterhub>=4,<5 +notebook pytest pytest-aiohttp pytest-asyncio pytest-cov +pytest-jupyterhub requests-mock diff --git a/pytest.ini b/pytest.ini index 0ee949b..cc244a3 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] python_files = test_*.py +asyncio_mode = auto diff --git a/tljh-plasma/tljh_plasma/tests/conftest.py b/tljh-plasma/tljh_plasma/tests/conftest.py index 2f21b20..1c80c27 100644 --- a/tljh-plasma/tljh_plasma/tests/conftest.py +++ b/tljh-plasma/tljh_plasma/tests/conftest.py @@ -1,17 +1,10 @@ import asyncio +import os import sys import pytest -from jupyterhub.tests.conftest import ( - io_loop, - event_loop, - db, - pytest_collection_modifyitems, -) -from jupyterhub.tests.mocking import MockHub, MockPAMAuthenticator from tljh_repo2docker.tests.conftest import ( - DummyConfig, minimal_repo, image_name, generated_image_name, @@ -20,40 +13,16 @@ from tljh_repo2docker.tests.utils import add_environment from tljh_repo2docker import tljh_custom_jupyterhub_config as tljh_repo2docker_config from tljh_plasma import tljh_custom_jupyterhub_config as tljh_plasma_config +from traitlets.config import Config -@pytest.fixture(scope="module") -def app(request, io_loop): - """ - Adapted from: - https://github.com/jupyterhub/jupyterhub/blob/8a3790b01ff944c453ffcc0486149e2a58ffabea/jupyterhub/tests/conftest.py#L74 - """ - - # create a JupyterHub mock instance - mocked_app = MockHub.instance() - c = DummyConfig() - c.JupyterHub = mocked_app - - # apply the config from the plugins - tljh_repo2docker_config(c) - tljh_plasma_config(c) - - # switch back to the MockPAMAuthenticator for the tests - c.JupyterHub.authenticator_class = MockPAMAuthenticator - - async def make_app(): - await mocked_app.initialize([]) - await mocked_app.start() +@pytest.fixture +async def app(hub_app): + config = Config() + config.authenticator_class = 'jupyterhub.tests.mocking.MockPAMAuthenticator' - def fin(): - # disconnect logging during cleanup because pytest closes captured FDs prematurely - mocked_app.log.handlers = [] - MockHub.clear_instance() - try: - mocked_app.stop() - except Exception as e: - print("Error stopping Hub: %s" % e, file=sys.stderr) + tljh_repo2docker_config(config) + tljh_plasma_config(config) - request.addfinalizer(fin) - io_loop.run_sync(make_app) - return mocked_app + app = await hub_app(config=config) + return app \ No newline at end of file