From 3043574eb07c12e45b7236411a8caae51c05d683 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 3 Nov 2021 06:43:41 -0400 Subject: [PATCH] tests: Use background fixture for each test Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- .../modules/matrixsynapse/tests/test_functional.py | 7 ++----- plinth/modules/zoph/tests/test_functional.py | 6 ++---- plinth/tests/functional/__init__.py | 12 +++++------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/plinth/modules/matrixsynapse/tests/test_functional.py b/plinth/modules/matrixsynapse/tests/test_functional.py index 7835368dd..893593ea9 100644 --- a/plinth/modules/matrixsynapse/tests/test_functional.py +++ b/plinth/modules/matrixsynapse/tests/test_functional.py @@ -17,18 +17,15 @@ class TestMatrixSynapseApp(functional.BaseAppTests): has_web = False @pytest.fixture(scope='class', autouse=True) - def fixture_background(self, session_browser): - """Login and install the app.""" + def fixture_setup(self, session_browser): + """Setup the app.""" functional.login(session_browser) functional.set_domain_name(session_browser, 'mydomain.example') functional.install(session_browser, self.app_name) functional.app_select_domain_name(session_browser, self.app_name, 'mydomain.example') - yield - functional.app_disable(session_browser, self.app_name) def test_run_diagnostics(self, session_browser): """Add a short delay before checking diagnostics.""" - functional.app_enable(session_browser, self.app_name) time.sleep(1) super().test_run_diagnostics(session_browser) diff --git a/plinth/modules/zoph/tests/test_functional.py b/plinth/modules/zoph/tests/test_functional.py index bbf56a8f5..4900ce741 100644 --- a/plinth/modules/zoph/tests/test_functional.py +++ b/plinth/modules/zoph/tests/test_functional.py @@ -15,13 +15,11 @@ class TestZophApp(functional.BaseAppTests): has_web = True @pytest.fixture(scope='class', autouse=True) - def fixture_background(self, session_browser): - """Login and install the app.""" + def fixture_setup(self, session_browser): + """Setup the app.""" functional.login(session_browser) functional.install(session_browser, self.app_name) self._zoph_is_setup(session_browser) - yield - functional.app_disable(session_browser, self.app_name) def _zoph_is_setup(self, session_browser): """Click setup button on the setup page.""" diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index 6c9bc73a0..7d4f8e2a0 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -616,30 +616,29 @@ class BaseAppTests: if self.has_web: assert not is_available(session_browser, self.app_name) - @pytest.fixture(scope='class', autouse=True) + @pytest.fixture(autouse=True) def fixture_background(self, session_browser): - """Login and install the app.""" + """Login, install, and enable the app.""" login(session_browser) install(session_browser, self.app_name) + app_enable(session_browser, self.app_name) yield + login(session_browser) app_disable(session_browser, self.app_name) def test_enable_disable(self, session_browser): """Test enabling and disabling the app.""" app_disable(session_browser, self.app_name) + self.assert_app_not_running(session_browser) app_enable(session_browser, self.app_name) self.assert_app_running(session_browser) - app_disable(session_browser, self.app_name) - self.assert_app_not_running(session_browser) - def test_run_diagnostics(self, session_browser): """Test that all app diagnostics are passing.""" if not self.check_diagnostics: pytest.skip(f'Skipping diagnostics check for ${self.app_name}.') - app_enable(session_browser, self.app_name) session_browser.find_by_id('id_extra_actions_button').click() submit(session_browser, form_class='form-diagnostics-button') @@ -654,7 +653,6 @@ class BaseAppTests: @pytest.mark.backups def test_backup_restore(self, session_browser): """Test that backup and restore operations work on the app.""" - app_enable(session_browser, self.app_name) backup_create(session_browser, self.app_name, 'test_' + self.app_name) backup_restore(session_browser, self.app_name, 'test_' + self.app_name) self.assert_app_running(session_browser)