diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2020-09-16 21:31:15 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2020-09-16 21:31:15 +0100 |
commit | d5e915934066c77a59d211efafca10c117b73d05 (patch) | |
tree | f894a3c09bd8aa43e87276eed377eb09f97e46fe /test/test_respawn.py | |
parent | 77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff) | |
download | unit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2 |
Tests: migrated to the pytest.
Diffstat (limited to 'test/test_respawn.py')
-rw-r--r-- | test/test_respawn.py | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/test/test_respawn.py b/test/test_respawn.py index f1c71a20..d40e78a4 100644 --- a/test/test_respawn.py +++ b/test/test_respawn.py @@ -3,6 +3,7 @@ import subprocess import time from unit.applications.lang.python import TestApplicationPython +from conftest import skip_alert class TestRespawn(TestApplicationPython): @@ -11,21 +12,20 @@ class TestRespawn(TestApplicationPython): PATTERN_ROUTER = 'unit: router' PATTERN_CONTROLLER = 'unit: controller' - def setUp(self): - super().setUp() + def setup_method(self): + super().setup_method() - self.app_name = "app-" + self.testdir.split('/')[-1] + self.app_name = "app-" + self.temp_dir.split('/')[-1] self.load('empty', self.app_name) - self.assertIn( - 'success', - self.conf('1', 'applications/' + self.app_name + '/processes') + assert 'success' in self.conf( + '1', 'applications/' + self.app_name + '/processes' ) def pid_by_name(self, name): output = subprocess.check_output(['ps', 'ax']).decode() - m = re.search('\s*(\d+).*' + name, output) + m = re.search(r'\s*(\d+).*' + name, output) return m if m is None else m.group(1) def kill_pids(self, *pids): @@ -44,27 +44,26 @@ class TestRespawn(TestApplicationPython): def smoke_test(self): for _ in range(5): - self.assertIn( - 'success', - self.conf('1', 'applications/' + self.app_name + '/processes') + assert 'success' in self.conf( + '1', 'applications/' + self.app_name + '/processes' ) - self.assertEqual(self.get()['status'], 200) + assert self.get()['status'] == 200 # Check if the only one router, controller, # and application processes running. output = subprocess.check_output(['ps', 'ax']).decode() - self.assertEqual(len(re.findall(self.PATTERN_ROUTER, output)), 1) - self.assertEqual(len(re.findall(self.PATTERN_CONTROLLER, output)), 1) - self.assertEqual(len(re.findall(self.app_name, output)), 1) + assert len(re.findall(self.PATTERN_ROUTER, output)) == 1 + assert len(re.findall(self.PATTERN_CONTROLLER, output)) == 1 + assert len(re.findall(self.app_name, output)) == 1 def test_respawn_router(self): pid = self.pid_by_name(self.PATTERN_ROUTER) self.kill_pids(pid) - self.skip_alerts.append(r'process %s exited on signal 9' % pid) + skip_alert(r'process %s exited on signal 9' % pid) - self.assertIsNotNone(self.wait_for_process(self.PATTERN_ROUTER)) + assert self.wait_for_process(self.PATTERN_ROUTER) is not None self.smoke_test() @@ -72,11 +71,11 @@ class TestRespawn(TestApplicationPython): pid = self.pid_by_name(self.PATTERN_CONTROLLER) self.kill_pids(pid) - self.skip_alerts.append(r'process %s exited on signal 9' % pid) + skip_alert(r'process %s exited on signal 9' % pid) - self.assertIsNotNone(self.wait_for_process(self.PATTERN_CONTROLLER)) + assert self.wait_for_process(self.PATTERN_CONTROLLER) is not None - self.assertEqual(self.get()['status'], 200) + assert self.get()['status'] == 200 self.smoke_test() @@ -84,12 +83,8 @@ class TestRespawn(TestApplicationPython): pid = self.pid_by_name(self.app_name) self.kill_pids(pid) - self.skip_alerts.append(r'process %s exited on signal 9' % pid) + skip_alert(r'process %s exited on signal 9' % pid) - self.assertIsNotNone(self.wait_for_process(self.app_name)) + assert self.wait_for_process(self.app_name) is not None self.smoke_test() - - -if __name__ == '__main__': - TestRespawn.main() |