diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index c180bea4d2..05e44cf29f 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -1839,7 +1839,7 @@ def list_running_servers(runtime_dir=None): return for file_name in os.listdir(runtime_dir): - if file_name.startswith('nbserver-'): + if re.match('nbserver-(.+).json', file_name): with io.open(os.path.join(runtime_dir, file_name), encoding='utf-8') as f: info = json.load(f) diff --git a/notebook/tests/test_notebookapp.py b/notebook/tests/test_notebookapp.py index 0c277e80d9..ff34a97776 100644 --- a/notebook/tests/test_notebookapp.py +++ b/notebook/tests/test_notebookapp.py @@ -25,6 +25,8 @@ from notebook.auth.security import passwd_check NotebookApp = notebookapp.NotebookApp +from .launchnotebook import NotebookTestBase + def test_help_output(): """ipython notebook --help-all works""" @@ -183,3 +185,10 @@ def list_running_servers(runtime_dir): app.start() nt.assert_equal(exc.exception.code, 1) nt.assert_equal(len(app.servers_shut_down), 0) + + +class NotebookAppTests(NotebookTestBase): + def test_list_running_servers(self): + servers = list(notebookapp.list_running_servers()) + assert len(servers) >= 1 + assert self.port in {info['port'] for info in servers}