From f0b091f27af7ea8b84537771bdb992b0125a1c9b Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Fri, 14 Jun 2019 11:28:42 +0300 Subject: [PATCH] Set port during tests - #139 changes port handling, this makes tests pass. - Sets attribute mock_port, which gets used during the port polling phase. --- batchspawner/batchspawner.py | 4 ++++ batchspawner/tests/test_spawners.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/batchspawner/batchspawner.py b/batchspawner/batchspawner.py index 885e020f..ed9d01b1 100644 --- a/batchspawner/batchspawner.py +++ b/batchspawner/batchspawner.py @@ -375,6 +375,10 @@ def start(self): self.ip = self.state_gethost() while self.port == 0: yield gen.sleep(self.startup_poll_interval) + # Test framework: For testing, mock_port is set because we + # don't actually run the single-user server yet. + if hasattr(self, 'mock_port'): + self.port = self.mock_port if jupyterhub.version_info < (0,7): # store on user for pre-jupyterhub-0.7: diff --git a/batchspawner/tests/test_spawners.py b/batchspawner/tests/test_spawners.py index 672ce395..2941e05d 100644 --- a/batchspawner/tests/test_spawners.py +++ b/batchspawner/tests/test_spawners.py @@ -64,7 +64,7 @@ def new_spawner(db, spawner_class=BatchDummy, **kwargs): kwargs.setdefault('server', server) kwargs.setdefault('hub', hub) kwargs.setdefault('user', user) - kwargs.setdefault('current_port', testport) + kwargs.setdefault('mock_port', testport) kwargs.setdefault('INTERRUPT_TIMEOUT', 1) kwargs.setdefault('TERM_TIMEOUT', 1) kwargs.setdefault('KILL_TIMEOUT', 1)