diff --git a/notebook/services/sessions/tests/test_sessionmanager.py b/notebook/services/sessions/tests/test_sessionmanager.py index dbb4feb5e..0b31d97a4 100644 --- a/notebook/services/sessions/tests/test_sessionmanager.py +++ b/notebook/services/sessions/tests/test_sessionmanager.py @@ -56,13 +56,10 @@ class TestSessionManager(TestCase): def create_session(self, **kwargs): return self.create_sessions(kwargs)[0] - def get_session(self, **kwargs): - return self.loop.run_sync(lambda : self.sm.get_session(**kwargs)) - def test_get_session(self): sm = self.sm session_id = self.create_session(path='/path/to/test.ipynb', kernel_name='bar')['id'] - model = self.get_session(session_id=session_id) + model = sm.get_session(session_id=session_id) expected = {'id':session_id, 'notebook':{'path': u'/path/to/test.ipynb'}, 'kernel': {'id':u'A', 'name': 'bar'}} @@ -140,7 +137,7 @@ class TestSessionManager(TestCase): session_id = self.create_session(path='/path/to/test.ipynb', kernel_name='julia')['id'] sm.update_session(session_id, path='/path/to/new_name.ipynb') - model = self.loop.run_sync(lambda : sm.get_session(session_id=session_id)) + model = sm.get_session(session_id=session_id) expected = {'id':session_id, 'notebook':{'path': u'/path/to/new_name.ipynb'}, 'kernel':{'id':u'A', 'name':'julia'}} diff --git a/notebook/tests/launchnotebook.py b/notebook/tests/launchnotebook.py index b957cdf4d..e9842ca43 100644 --- a/notebook/tests/launchnotebook.py +++ b/notebook/tests/launchnotebook.py @@ -19,6 +19,7 @@ except ImportError: from tornado.ioloop import IOLoop +import jupyter_core.paths from ..notebookapp import NotebookApp from ipython_genutils.tempdir import TemporaryDirectory @@ -51,9 +52,8 @@ class NotebookTestBase(TestCase): try: requests.get(url) except Exception as e: - if cls.notebook.poll() is not None: - raise RuntimeError("The notebook server exited with status %s" \ - % cls.notebook.poll()) + if not cls.notebook_thread.is_alive(): + raise RuntimeError("The notebook server failed to start") time.sleep(POLL_INTERVAL) else: return @@ -77,31 +77,35 @@ class NotebookTestBase(TestCase): 'JUPYTER_DATA_DIR' : data_dir.name }) cls.env_patch.start() + cls.path_patch = patch.object(jupyter_core.paths, 'SYSTEM_JUPYTER_PATH', []) + cls.path_patch.start() cls.config_dir = TemporaryDirectory() cls.data_dir = data_dir cls.runtime_dir = TemporaryDirectory() cls.notebook_dir = TemporaryDirectory() - app = cls.notebook = NotebookApp( - port=cls.port, - port_retries=0, - open_browser=False, - config_dir=cls.config_dir.name, - data_dir=cls.data_dir.name, - runtime_dir=cls.runtime_dir.name, - notebook_dir=cls.notebook_dir.name, - base_url=cls.url_prefix, - config=cls.config, - ) - # clear log handlers and propagate to root for nose to capture it - # needs to be redone after initialize, which reconfigures logging - app.log.propagate = True - app.log.handlers = [] - app.initialize(argv=[]) - app.log.propagate = True - app.log.handlers = [] started = Event() def start_thread(): + app = cls.notebook = NotebookApp( + port=cls.port, + port_retries=0, + open_browser=False, + config_dir=cls.config_dir.name, + data_dir=cls.data_dir.name, + runtime_dir=cls.runtime_dir.name, + notebook_dir=cls.notebook_dir.name, + base_url=cls.url_prefix, + config=cls.config, + ) + # don't register signal handler during tests + app.init_signal = lambda : None + # clear log handlers and propagate to root for nose to capture it + # needs to be redone after initialize, which reconfigures logging + app.log.propagate = True + app.log.handlers = [] + app.initialize(argv=[]) + app.log.propagate = True + app.log.handlers = [] loop = IOLoop.current() loop.add_callback(started.set) try: @@ -109,6 +113,7 @@ class NotebookTestBase(TestCase): finally: # set the event, so failure to start doesn't cause a hang started.set() + app.session_manager.close() cls.notebook_thread = Thread(target=start_thread) cls.notebook_thread.start() started.wait() @@ -118,12 +123,13 @@ class NotebookTestBase(TestCase): def teardown_class(cls): cls.notebook.stop() cls.wait_until_dead() - cls.env_patch.start() cls.home_dir.cleanup() cls.config_dir.cleanup() cls.data_dir.cleanup() cls.runtime_dir.cleanup() cls.notebook_dir.cleanup() + cls.env_patch.stop() + cls.path_patch.stop() @classmethod def base_url(cls):