plasmabio / tljh-repo2docker

Plugin for The Littlest JupyterHub to build multiple user environments with repo2docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use `pytest-jupyterhub` for testing

jtpio opened this issue · comments

There is now a Pytest plugin for JupyterHub: https://github.com/jupyterhub/pytest-jupyterhub

We should look into using it to simplify the current conftest:

@pytest.fixture(scope='module')
def app(request, io_loop):
"""
Adapted from:
https://github.com/jupyterhub/jupyterhub/blob/8a3790b01ff944c453ffcc0486149e2a58ffabea/jupyterhub/tests/conftest.py#L74
"""
mocked_app = MockHub.instance()
c = DummyConfig()
c.JupyterHub = mocked_app
tljh_custom_jupyterhub_config(c)
async def make_app():
await mocked_app.initialize([])
await mocked_app.start()
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)
request.addfinalizer(fin)
io_loop.run_sync(make_app)
return mocked_app