diff --git a/README.md b/README.md index 2ab3eb18..a6cb39b5 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Status](https://img.shields.io/pypi/v/testit-python-commons?style=plastic)](http - importRealtime=false is a default mode (previously true) - **limitations**: -- The current 4.0.0 version is not compatible with `adapterMode=2` when using parallelization (e.g., `pytest --testit -n 4`). Please use `adapterMode=1`. +- Versions before 4.2.2 are not compatible with `adapterMode=2` when using parallelization (e.g., `pytest --testit -n 4`). Please use `adapterMode=1`or update to 4.2.2+ . ### How to run 4.0+ locally? diff --git a/testit-adapter-behave/setup.py b/testit-adapter-behave/setup.py index f807fb5b..e4f2348a 100644 --- a/testit-adapter-behave/setup.py +++ b/testit-adapter-behave/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.2.0" +VERSION = "4.2.2" setup( name='testit-adapter-behave', diff --git a/testit-adapter-nose/setup.py b/testit-adapter-nose/setup.py index 13c2cffc..4bd05cff 100644 --- a/testit-adapter-nose/setup.py +++ b/testit-adapter-nose/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = "4.2.0" +VERSION = "4.2.2" setup( name='testit-adapter-nose', diff --git a/testit-adapter-pytest/setup.py b/testit-adapter-pytest/setup.py index a81a3b90..bb0fad38 100644 --- a/testit-adapter-pytest/setup.py +++ b/testit-adapter-pytest/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.2.0" +VERSION = "4.2.2" setup( name='testit-adapter-pytest', diff --git a/testit-adapter-pytest/src/testit_adapter_pytest/listener.py b/testit-adapter-pytest/src/testit_adapter_pytest/listener.py index 661fb23d..dbbe8c9d 100644 --- a/testit-adapter-pytest/src/testit_adapter_pytest/listener.py +++ b/testit-adapter-pytest/src/testit_adapter_pytest/listener.py @@ -82,16 +82,16 @@ def __init__(self, adapter_manager: AdapterManager, step_manager: StepManager, f def pytest_configure(self, config): self.__pytest_info = metadata("pytest") - if not hasattr(config, "workerinput") and not hasattr(self, "test_run_id"): - config.test_run_id = self.__adapter_manager.get_test_run_id() - else: + if hasattr(config, "workerinput"): config.test_run_id = pickle.loads(config.workerinput["test_run_id"]) + elif not hasattr(config, "test_run_id"): + config.test_run_id = self.__adapter_manager.get_test_run_id() self.__adapter_manager.set_test_run_id(config.test_run_id) @pytest.hookimpl def pytest_configure_node(self, node): - if not hasattr(self, "test_run_id"): + if hasattr(node.config, "test_run_id"): node.workerinput["test_run_id"] = pickle.dumps(node.config.test_run_id) @adapter.hookimpl diff --git a/testit-adapter-robotframework/setup.py b/testit-adapter-robotframework/setup.py index 58cbaea2..211ae727 100644 --- a/testit-adapter-robotframework/setup.py +++ b/testit-adapter-robotframework/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.2.0" +VERSION = "4.2.2" setup( name='testit-adapter-robotframework', diff --git a/testit-python-commons/setup.py b/testit-python-commons/setup.py index f90eab5f..f905e7b8 100644 --- a/testit-python-commons/setup.py +++ b/testit-python-commons/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.2.0" +VERSION = "4.2.2" setup( name='testit-python-commons', diff --git a/testit-python-commons/src/testit_python_commons/services/adapter_manager.py b/testit-python-commons/src/testit_python_commons/services/adapter_manager.py index 5b0848fc..b02931ae 100644 --- a/testit-python-commons/src/testit_python_commons/services/adapter_manager.py +++ b/testit-python-commons/src/testit_python_commons/services/adapter_manager.py @@ -48,45 +48,44 @@ def __init__( def _initialize_sync_storage(self, client_configuration: ClientConfiguration): """Initialize Sync Storage runner if enabled.""" - try: - # Get test run ID - create one if needed - test_run_id = self.__config.get_test_run_id() + if client_configuration.is_legacy_workflow(): + return None - # If no test run ID, create one (as in Java implementation) - if not test_run_id: - test_run_id = self.__api_client.create_test_run( - self.__config.get_test_run_name() - ) - self.__config.set_test_run_id(test_run_id) - self.__api_client.set_test_run_id(test_run_id) - - # Extract configuration properties - url = client_configuration.get_url() - private_token = client_configuration.get_private_token() - port = client_configuration.get_sync_storage_port() - print(f'sync storage port: {port}') - - # Create and start Sync Storage runner - if SYNC_STORAGE_AVAILABLE: - sync_storage_runner = SyncStorageRunner( - test_run_id=test_run_id, - port=port, - base_url=url, - private_token=private_token, - ) + test_run_id = self.__config.get_test_run_id() + if not test_run_id and self.__config.get_mode() == AdapterMode.NEW_TEST_RUN: + return None + + if not test_run_id: + logging.warning('Sync Storage requires test run ID; skipping initialization') + return None + + return self._start_sync_storage(test_run_id, client_configuration) - if sync_storage_runner.start(): - logging.info("Sync Storage started successfully") - return sync_storage_runner - else: - logging.warning("Failed to start Sync Storage") + def _start_sync_storage( + self, + test_run_id: str, + client_configuration: ClientConfiguration): + try: + if not SYNC_STORAGE_AVAILABLE: + return None + + sync_storage_runner = SyncStorageRunner( + test_run_id=test_run_id, + port=client_configuration.get_sync_storage_port(), + base_url=client_configuration.get_url(), + private_token=client_configuration.get_private_token(), + ) + + if sync_storage_runner.start(): + logging.info("Sync Storage started successfully") + return sync_storage_runner + logging.warning("Failed to start Sync Storage") except Exception as e: logging.warning(f"Failed to initialize SyncStorage: {e}", exc_info=True) return None - @adapter_logger def set_test_run_id(self, test_run_id: str) -> None: @@ -94,9 +93,13 @@ def set_test_run_id(self, test_run_id: str) -> None: self.__api_client.set_test_run_id(test_run_id) - # Update Sync Storage with test run ID if available if self.__sync_storage_runner: self.__sync_storage_runner.test_run_id = test_run_id + return + + if SYNC_STORAGE_AVAILABLE and not self.__client_config.is_legacy_workflow(): + self.__sync_storage_runner = self._start_sync_storage( + test_run_id, self.__client_config) @adapter_logger def get_test_run_id(self) -> str: diff --git a/testit-python-commons/tests/services/test_adapter_manager.py b/testit-python-commons/tests/services/test_adapter_manager.py index 987ed38f..f5f9fa8a 100644 --- a/testit-python-commons/tests/services/test_adapter_manager.py +++ b/testit-python-commons/tests/services/test_adapter_manager.py @@ -192,6 +192,51 @@ def test_create_attachment_with_name(self, adapter_manager, mock_api_client_work mock_os_remove.assert_called_once_with(expected_file_path) assert attachment_id == expected_attachment_id + def test_init_does_not_create_test_run_for_new_test_run_mode_without_id( + self, + mocker, + mock_adapter_config, + mock_client_config, + mock_fixture_manager, + mock_api_client_worker): + mock_adapter_config.get_mode.return_value = AdapterMode.NEW_TEST_RUN + mock_adapter_config.get_test_run_id.return_value = None + mock_client_config.is_legacy_workflow.return_value = False + start_sync_storage = mocker.patch.object( + AdapterManager, + "_start_sync_storage", + return_value=None, + ) + + AdapterManager( + adapter_configuration=mock_adapter_config, + client_configuration=mock_client_config, + fixture_manager=mock_fixture_manager, + ) + + mock_api_client_worker.create_test_run.assert_not_called() + start_sync_storage.assert_not_called() + + def test_set_test_run_id_starts_sync_storage_when_deferred( + self, + adapter_manager, + mock_client_config, + mocker): + test_run_id = str(uuid.uuid4()) + sync_storage_runner = mocker.Mock() + start_sync_storage = mocker.patch.object( + adapter_manager, + "_start_sync_storage", + return_value=sync_storage_runner, + ) + mock_client_config.is_legacy_workflow.return_value = False + adapter_manager._AdapterManager__sync_storage_runner = None + + adapter_manager.set_test_run_id(test_run_id) + + start_sync_storage.assert_called_once_with(test_run_id, mock_client_config) + assert adapter_manager._AdapterManager__sync_storage_runner is sync_storage_runner + def test_init_does_not_start_sync_storage_in_legacy_workflow( self, mocker, diff --git a/update_versions.sh b/update_versions.sh index b13d17d1..6aa9dac2 100644 --- a/update_versions.sh +++ b/update_versions.sh @@ -1,6 +1,6 @@ #!/bin/bash -NEW_VERSION="4.2.0" +NEW_VERSION="4.2.2" TESTIT_API_CLIENT_VERSION="7.5.6" echo "Updating all adapters to version: $NEW_VERSION"