diff --git a/README.md b/README.md index 555696b..e5aeb5d 100644 --- a/README.md +++ b/README.md @@ -170,13 +170,14 @@ You can use environment variable to control certain features of testomat.io #### Test Run configuration -| Env variable | What it does | Examples | -|--------------------------|----------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------| -| TESTOMATIO_TITLE | Name of a test run to create on testomat.io | TESTOMATIO_TITLE="Nightly Smoke Tests" pytest --testomatio report | -| TESTOMATIO_RUN_ID | Id of existing test run to use for sending test results to | TESTOMATIO_RUN_ID=98dfas0 pytest --testomatio report | -| TESTOMATIO_RUNGROUP_TITLE | Create a group (folder) for a test run. If group already exists, attach test run to it | TESTOMATIO_RUNGROUP_TITLE="Release 2.0" pytest --testomatio report | -| TESTOMATIO_ENV | Assign environment to a test run, env variant of **testRunEnv** option. Has a lower precedence than **testRunEnv** option. | TESTOMATIO_ENV="linux,chrome,1920x1080" pytest --testomatio report | -| TESTOMATIO_LABEL | Assign labels to a test run. Labels must exist in project and their scope must be enabled for runs | TESTOMATIO_LABEL="smoke,regression" pytest --testomatio report | +| Env variable | What it does | Examples | +|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------| +| TESTOMATIO_TITLE | Name of a test run to create on testomat.io | TESTOMATIO_TITLE="Nightly Smoke Tests" pytest --testomatio report | +| TESTOMATIO_RUN_ID | Id of existing test run to use for sending test results to | TESTOMATIO_RUN_ID=98dfas0 pytest --testomatio report | +| TESTOMATIO_RUNGROUP_TITLE | Create a group (folder) for a test run. If group already exists, attach test run to it | TESTOMATIO_RUNGROUP_TITLE="Release 2.0" pytest --testomatio report | +| TESTOMATIO_ENV | Assign environment to a test run, env variant of **testRunEnv** option. Has a lower precedence than **testRunEnv** option. | TESTOMATIO_ENV="linux,chrome,1920x1080" pytest --testomatio report | +| TESTOMATIO_LABEL | Assign labels to a test run. Labels must exist in project and their scope must be enabled for runs | TESTOMATIO_LABEL="smoke,regression" pytest --testomatio report | +| TESTOMATIO_JIRA_ID | Assigns Test Run to Jira Issue. Note: Issue must exist on Jira and Jira Integration must be configured for project on Testomat.io | TESTOMATIO_JIRA_ID=TES-1 pytest --testomatio report | #### S3 Bucket configuration | Env variable | Description | diff --git a/pyproject.toml b/pyproject.toml index 472690c..f182548 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.10.1" +version = "2.10.2b7" dependencies = [ diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index d7004c6..26d2dbc 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -120,12 +120,13 @@ def get_tests(self, test_metadata: list[TestItem]) -> dict: response = self.session.get(f'{self.base_url}/api/test_data?api_key={self.api_key}') return response.json() - def create_test_run(self, title: str, group_title, env: str, label: str, shared_run: bool, parallel, ci_build_url: str) -> dict | None: + def create_test_run(self, title: str, group_title, env: str, jira_id: str, label: str, shared_run: bool, parallel, ci_build_url: str) -> dict | None: request = { "api_key": self.api_key, "title": title, "group_title": group_title, "env": env, + "jira_id": jira_id, "label": label, "parallel": parallel, "ci_build_url": ci_build_url, @@ -148,13 +149,14 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ log.info(f'Test run created {response.json()["uid"]}') return response.json() - def update_test_run(self, id: str, title: str, group_title, + def update_test_run(self, id: str, title: str, group_title, jira_id: str, env: str, label: str, shared_run: bool, parallel, ci_build_url: str) -> dict | None: request = { "api_key": self.api_key, "title": title, "group_title": group_title, "env": env, + "jira_id": jira_id, "label": label, "parallel": parallel, "ci_build_url": ci_build_url, diff --git a/pytestomatio/testomatio/testRunConfig.py b/pytestomatio/testomatio/testRunConfig.py index b58421f..6db321f 100644 --- a/pytestomatio/testomatio/testRunConfig.py +++ b/pytestomatio/testomatio/testRunConfig.py @@ -16,6 +16,7 @@ def __init__(self): self.environment = safe_string_list(os.environ.get('TESTOMATIO_ENV')) self.label = safe_string_list(os.environ.get('TESTOMATIO_LABEL')) self.group_title = os.environ.get('TESTOMATIO_RUNGROUP_TITLE') + self.jira_id = os.environ.get('TESTOMATIO_JIRA_ID') # This allows to report tests to the test run by it's id. https://docs.testomat.io/getting-started/running-automated-tests/#reporting-parallel-tests self.parallel = False if shared_run else True # This allows using test run title to group tests under a single test run. This is needed when running tests in different processes or servers. @@ -30,6 +31,7 @@ def to_dict(self) -> dict: result['title'] = self.title result['group_title'] = self.group_title result['env'] = self.environment + result['jira_id'] = self.jira_id result['label'] = self.label result['parallel'] = self.parallel result['shared_run'] = self.shared_run diff --git a/tests/test_connect/test_connector.py b/tests/test_connect/test_connector.py index c4d3016..5023552 100644 --- a/tests/test_connect/test_connector.py +++ b/tests/test_connect/test_connector.py @@ -143,6 +143,7 @@ def test_create_test_run_success(self, mock_post, connector): group_title="Group 1", env="linux,chrome", label="smoke", + jira_id="tes-1", shared_run=False, parallel=True, ci_build_url="https://ci.example.com/build/123" @@ -155,6 +156,7 @@ def test_create_test_run_success(self, mock_post, connector): "title": "Test Run", "group_title": "Group 1", "env": "linux,chrome", + "jira_id": "tes-1", "label": "smoke", "shared_run": False, "parallel": True, @@ -177,6 +179,7 @@ def test_create_test_run_filters_none_values(self, mock_post, connector): group_title=None, env=None, label="smoke", + jira_id=None, shared_run=False, parallel=True, ci_build_url=None @@ -197,7 +200,7 @@ def test_create_test_run_http_error(self, mock_post, connector): """Test HTTP error handled wher create test run""" mock_post.side_effect = HTTPError("HTTP Error") - result = connector.create_test_run("Test", None, None, None, False, True, None) + result = connector.create_test_run("Test", None, None, None, None, False, True, None) assert result is None @@ -214,6 +217,7 @@ def test_update_test_run_success(self, mock_put, connector): title="Updated Run", group_title="Group", env="windows", + jira_id="tes-1", label="regression", shared_run=True, parallel=False, @@ -227,6 +231,7 @@ def test_update_test_run_success(self, mock_put, connector): "title": "Updated Run", "group_title": "Group", "env": "windows", + "jira_id": "tes-1", "label": "regression", "shared_run": True, "parallel": False, diff --git a/tests/test_testomatio/test_testRunConfig.py b/tests/test_testomatio/test_testRunConfig.py index 3acad4b..ff85912 100644 --- a/tests/test_testomatio/test_testRunConfig.py +++ b/tests/test_testomatio/test_testRunConfig.py @@ -20,6 +20,7 @@ def test_init_default_values(self): assert config.title == "test run at 2024-01-15 10:30:45" assert config.environment is None assert config.label is None + assert config.jira_id is None assert config.group_title is None assert config.parallel is True assert config.shared_run is False @@ -32,7 +33,8 @@ def test_init_with_env_variables(self): 'TESTOMATIO_TITLE': 'Custom Test Run', 'TESTOMATIO_ENV': 'linux,chrome,1920x1080', 'TESTOMATIO_LABEL': 'smoke,regression', - 'TESTOMATIO_RUNGROUP_TITLE': 'Release 2.0' + 'TESTOMATIO_RUNGROUP_TITLE': 'Release 2.0', + 'TESTOMATIO_JIRA_ID': 'TES-1' } with patch.dict(os.environ, env_vars, clear=True): @@ -45,6 +47,7 @@ def test_init_with_env_variables(self): assert config.group_title == 'Release 2.0' assert config.parallel is True assert config.shared_run is False + assert config.jira_id == 'TES-1' @pytest.mark.parametrize('value', ['True', 'true', '1']) def test_init_shared_run_true_variations(self, value): @@ -72,7 +75,8 @@ def test_to_dict_full_data(self): 'TESTOMATIO_ENV': 'env1,env2', 'TESTOMATIO_LABEL': 'label1,label2', 'TESTOMATIO_RUNGROUP_TITLE': 'Group 1', - 'TESTOMATIO_SHARED_RUN': 'true' + 'TESTOMATIO_SHARED_RUN': 'true', + 'TESTOMATIO_JIRA_ID': "TES-1" } with patch.dict(os.environ, env_vars, clear=True): @@ -88,7 +92,8 @@ def test_to_dict_full_data(self): 'label': 'label1,label2', 'parallel': False, 'shared_run': True, - 'ci_build_url': None + 'ci_build_url': None, + 'jira_id': 'TES-1' } assert result == expected