##// END OF EJS Templates
don't start new notebook server for each test *method*...
MinRK -
Show More
@@ -18,45 +18,52 b' class NotebookTestBase(TestCase):'
18 18
19 19 port = 12341
20 20
21 def wait_till_alive(self):
22 url = 'http://localhost:%i/' % self.port
21 @classmethod
22 def wait_until_alive(cls):
23 """Wait for the server to be alive"""
24 url = 'http://localhost:%i/api/notebooks' % cls.port
23 25 while True:
24 time.sleep(.1)
25 26 try:
26 r = requests.get(url + 'api/notebooks')
27 break
27 requests.get(url)
28 28 except requests.exceptions.ConnectionError:
29 pass
29 time.sleep(.1)
30 else:
31 break
30 32
31 def wait_till_dead(self):
32 url = 'http://localhost:%i/' % self.port
33 @classmethod
34 def wait_until_dead(cls):
35 """Wait for the server to stop getting requests after shutdown"""
36 url = 'http://localhost:%i/api/notebooks' % cls.port
33 37 while True:
34 time.sleep(.1)
35 38 try:
36 r = requests.get(url + 'api/notebooks')
37 continue
39 requests.get(url)
38 40 except requests.exceptions.ConnectionError:
39 41 break
42 else:
43 time.sleep(.1)
40 44
41 def setUp(self):
42 self.ipython_dir = TemporaryDirectory()
43 self.notebook_dir = TemporaryDirectory()
45 @classmethod
46 def setup_class(cls):
47 cls.ipython_dir = TemporaryDirectory()
48 cls.notebook_dir = TemporaryDirectory()
44 49 notebook_args = [
45 50 sys.executable, '-c',
46 51 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
47 '--port=%d' % self.port,
52 '--port=%d' % cls.port,
48 53 '--no-browser',
49 '--ipython-dir=%s' % self.ipython_dir.name,
50 '--notebook-dir=%s' % self.notebook_dir.name
54 '--ipython-dir=%s' % cls.ipython_dir.name,
55 '--notebook-dir=%s' % cls.notebook_dir.name
51 56 ]
52 self.notebook = Popen(notebook_args, stdout=PIPE, stderr=PIPE)
53 self.wait_till_alive()
57 cls.notebook = Popen(notebook_args, stdout=PIPE, stderr=PIPE)
58 cls.wait_until_alive()
54 59
55 def tearDown(self):
56 self.notebook.terminate()
57 self.ipython_dir.cleanup()
58 self.notebook_dir.cleanup()
59 self.wait_till_dead()
60 @classmethod
61 def teardown_class(cls):
62 cls.notebook.terminate()
63 cls.ipython_dir.cleanup()
64 cls.notebook_dir.cleanup()
65 cls.wait_until_dead()
60 66
61 def base_url(self):
62 return 'http://localhost:%i/' % self.port
67 @classmethod
68 def base_url(cls):
69 return 'http://localhost:%i/' % cls.port
General Comments 0
You need to be logged in to leave comments. Login now