Skip to content

Commit

Permalink
Update testing for JupyterHub 4
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Nov 27, 2023
1 parent 8ad60ae commit ddfd913
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 44 deletions.
7 changes: 4 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
git+https://github.com/jupyterhub/[email protected]
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
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
python_files = test_*.py
asyncio_mode = auto
51 changes: 10 additions & 41 deletions tljh-plasma/tljh_plasma/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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

0 comments on commit ddfd913

Please sign in to comment.