From 57a6140d9b60d5d55923c36a2d267780e55993ae Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 10:53:57 +0100 Subject: [PATCH 01/15] feat: Add https://www.conventionalcommits.org/en/v1.0.0/ support --- .gitignore | 2 +- README.md | 8 +++++++- pyproject.toml | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 346b070..f89fa9d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ # file for test and debug temp_test.py build -pytest_analyzer.egg-info +pytest*.egg-info dist .venv* pytest.ini \ No newline at end of file diff --git a/README.md b/README.md index f3415dc..3c6a90d 100644 --- a/README.md +++ b/README.md @@ -258,4 +258,10 @@ def test_example(): ## TODO - Fix test duration - Require more back references from testomatio -- pytest.skip should behave as @pytest.mark.skip \ No newline at end of file +- pytest.skip should behave as @pytest.mark.skip + +## Contribution +1. `pip install -e .` +2. `cz commit` +3. `cz bump` +4. `git push remoteName branchName --tags` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9d28269..ce68b19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,17 @@ [build-system] -requires = ["setuptools>=65.5.1", "requests>=2.29.0", "pytest<8.0.0,>=7.3.1", "boto3>=1.28.28", "libcst==1.1.0"] +requires = ["setuptools>=65.5.1", "requests>=2.29.0", "pytest<8.0.0,>=7.3.1", "boto3>=1.28.28", "libcst==1.1.0", "commitizen>=3.18.1"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] exclude = [".github", "tests"] + +[tool.commitizen] +name = "cz_conventional_commits" +tag_format = "$version" +version_scheme = "pep440" +version_provider = "pep621" +update_changelog_on_bump = true [project] name = "pytestomatio" version = "2.1.2" From ddff267b539c0822064243fb0de6690cbe7dba6d Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 10:55:33 +0100 Subject: [PATCH 02/15] fix: Fix syncing local test with testomatio that are imported in a custom folder (on testomatio end) --- pytestomatio/helper.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pytestomatio/helper.py b/pytestomatio/helper.py index 4473b65..773d960 100644 --- a/pytestomatio/helper.py +++ b/pytestomatio/helper.py @@ -1,3 +1,4 @@ +from os.path import basename from pytest import Item from .testomat_item import TestomatItem from .testItem import TestItem @@ -63,11 +64,19 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, tcm_test_data = parse_test_list(testomatio_tests) for test in meta: for tcm_test in tcm_test_data: - if test.resync_title == tcm_test.title and test.file_name == tcm_test.file_name: + if not tcm_test.file_name: + continue + # Test that are synced into user specified folder - might end up with altered file path in testomatio + # making file path not match between source code and testomatio + # to mitigate this we compare only file names, skipping the path + # while it works it might not be the most reliable approach + # however, the underlying issue is the ability to alter the file path in testomatio + # https://github.com/testomatio/check-tests?tab=readme-ov-file#import-into-a-specific-suite + if test.resync_title == tcm_test.title and basename(test.file_name) == basename(tcm_test.file_name): test.id = tcm_test.id tcm_test_data.remove(tcm_test) break mapping = get_test_mapping(meta) for test_file in test_files: - update_tests(test_file, mapping, test_names, decorator_name) + update_tests(test_file, mapping, test_names, decorator_name) \ No newline at end of file From f92b88968a0f18c31c100bac210e20c7728deeca Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 10:55:37 +0100 Subject: [PATCH 03/15] =?UTF-8?q?bump:=20version=202.1.2=20=E2=86=92=202.2?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 64 -------------------------- pyproject.toml | 2 +- 3 files changed, 120 insertions(+), 65 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..23ecdda --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,119 @@ +## 2.2.0 (2024-03-11) + +### Feat + +- Add https://www.conventionalcommits.org/en/v1.0.0/ support + +### Fix + +- Fix syncing local test with testomatio that are imported in a custom folder (on testomatio end) +- Fix test run completion + +## 2.1.0 (2024-03-07) + +### Feat + +- Added support for `TESTOMATIO_TITLE`, `TESTOMATIO_SHARED_RUN` and `TESTOMATIO_LABEL` + +## 2.0.0 (2024-03-05) + +### Feat + +- Align naming with Testomat.io branding +- add --directory option to import test into specific directory in testomat.io + +## 1.7 (2024-02-26) + +### Fix + +- Fixes parameterized test sync and report + +### 1.6.0 (2024-02-21) + +### Feat + +- Add helped to attach test artifacts +- Expose environment variables to provide access to cloud storage +- Update readme + +### Fix + +- Testomaito not longer supports nested test suites. Suites could be only in a folder. + + +### 1.5.0 (2024-02-12) + +### Fix +- Fixes artifacts in fixtures lifecycle +- Earlier, artifacts added in pytest fixtures where skipped by analyser + +### 1.4.0 (2024-02-06) + +### Feat + +- Adds `--create`, `--no-detached`, `--keep-structure`, `--no-empty`, for compatibility with original Testomatio check-tests +- Improves file update so it doesn't cause code style changes + +### Fix +- Fixes artifacts uploads and test sync with Testomatio +- Fixes test id resolution when syncing local test with Testomatio +- Fixes test id when sending test into test run + +### 1.3.0 (2023-12-06) + +### Fix + +- [issue 5](https://github.com/Ypurek/pytest-analyzer/issues/5) - connection issues not blocking test execution anymore + +### 1.2.8 (2023-12-06) + +### Fix + +- [issue 4](https://github.com/Ypurek/pytest-analyzer/issues/4) - Analyzer's execution order + +### 1.2.5 (2023-10-21) + +### Feat + +- added env variable `TESTOMATIO_RUNGROUP_TITLE` to group test runs + +### Fix + +- fixed serialization issue for update test status example + +### 1.2.4 (2023-09-05) + +### Fix + +- improved parametrized tests reporting +- now parameters are passed to example attribute in the report + +### 1.2.3 (2023-09-03) + +### Fix + +- fixed issue with test artifacts when no credentials provided, test artifacts will not be uploaded and no issue raised + +### 1.2.0 (2023-08-20) + +### Fix + +- code refactored (Testomatio.io team review) +- simplified authentication. Only API key needed +- moved API key from pytest.ini to environment variable +- S3 credentials now read from testomat.io API, no local configuration needed +- Prettified test names in testomat.io + +### 1.1.1 (2023-08-17) + +### Feat + +- added artifacts support (screenshots, logs) to test report + +### 1.0.9 (2023-07-31) + +### Feat +- first public release +- test analyzer able to sync tests with testomat.io +- test analyzer able to add test ids to tests +- test analyzer able to submit test results to testomat.io \ No newline at end of file diff --git a/README.md b/README.md index 3c6a90d..1c2d979 100644 --- a/README.md +++ b/README.md @@ -184,70 +184,6 @@ def test_example(): | Debugging | parity | `pytest --testomatio debug` | -## Change log - -### 2.1.0 -- Added support for `TESTOMATIO_TITLE`, `TESTOMATIO_SHARED_RUN` and `TESTOMATIO_LABEL` - -### 2.0.0 - Reunion -- Align naming with Testomat.io branding -- add --directory option to import test into specific directory in testomat.io - -### 1.7.0 - Fixes parameterized test sync and report - -### 1.6.0 - Fixes nested suites -- Testomaito not longer supports nested test suites. Suites could be only in a folder. -- Add helped to attach test artifacts -- Expose environment variables to provide access to cloud storage -- Update readme - -### 1.5.0 - Fixes artifacts in fixtures lifecycle -- Earlier, artifacts added in pytest fixtures where scipped by analyser - -### 1.4.0 - Fixes artifacts and test sync with Testomatio -- Fixes artifacts uploads -- Fixes test id resolution when syncing local test with Testomatio -- Fixes test id when sending test into test run -- Adds `--create`, `--no-detached`, `--keep-structure`, `--no-empty`, for compatibility with original Testomatio check-tests -- Improves file update so it doesn't cause code style changes - -### 1.3.0 - added artifacts support connector -- [issue 5](https://github.com/Ypurek/pytest-analyzer/issues/5) - connection issues not blocking test execution anymore - -### 1.2.8 - fixed issues -- [issue 4](https://github.com/Ypurek/pytest-analyzer/issues/4) - Analyzer's execution order - -### 1.2.5 - fixed issues - -- added env variable `TESTOMATIO_RUNGROUP_TITLE` to group test runs -- fixed serialization issue for update test status example - -### 1.2.4 - improved parametrized tests reporting - -- now parameters are passed to example attribute in the report - -### 1.2.3 - fixed issue with test artifacts - -- if no credentials provided, test artifacts will not be uploaded and no issue raised - -### 1.2.0 - major update after testomat.io review - -- code refactored -- simplified authentication. Only API key needed -- moved API key from pytest.ini to environment variable -- S3 credentials now read from testomat.io API, no local configuration needed -- Prettified test names in testomat.io - -### 1.1.0 - added artifacts support connector - -- there is possibility to add artifacts (screenshots, logs) to test report - -### 1.0.9 - first public release - -- test analyzer able to sync tests with testomat.io -- test analyzer able to add test ids to tests -- test analyzer able to submit test results to testomat.io - ## Test - import into empty project - updated test - (resync) diff --git a/pyproject.toml b/pyproject.toml index ce68b19..7b2d88f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.1.2" +version = "2.2.0" dependencies = [ "requests>=2.29.0", From e677a162a25b03c1c44b171fcb842165f78ca517 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 19:00:57 +0100 Subject: [PATCH 04/15] feat: Add TESTOMATIO_RUN to support test runs created on testomatio https://github.com/testomatio/reporter/blob/master/docs/pipes/testomatio.md#add-report-to-run-by-id --- pytestomatio/connector.py | 27 +++++++++++++++++++++++++++ pytestomatio/main.py | 29 ++++++++++++++++------------- pytestomatio/testRunConfig.py | 5 ++++- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/pytestomatio/connector.py b/pytestomatio/connector.py index afb1020..69cbb90 100644 --- a/pytestomatio/connector.py +++ b/pytestomatio/connector.py @@ -93,6 +93,33 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ if response.status_code == 200: log.info(f'Test run created {response.json()["uid"]}') return response.json() + + def update_test_run(self, id: str, title: str, group_title, env: str, label: str, shared_run: bool, parallel) -> dict | None: + request = { + "title": title, + "group_title": group_title, + "env": env, + "label": label, + "parallel": parallel, + "shared_run": shared_run + } + filtered_request = {k: v for k, v in request.items() if v is not None} + + try: + response = self.session.put(f'{self.base_url}/api/reporter/{id}?api_key={self.api_key}', json=filtered_request) + except ConnectionError: + log.error(f'Failed to connect to {self.base_url}') + return + except HTTPError: + log.error(f'Failed to connect to {self.base_url}') + return + except Exception as e: + log.error(f'Generic exception happened. Please report an issue. {e}') + return + + if response.status_code == 200: + log.info(f'Test run updated {response.json()["uid"]}') + return response.json() def update_test_status(self, run_id: str, status: str, diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 1e776cb..3a1483c 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -92,6 +92,7 @@ def pytest_configure(config: Config): pytest.testomatio = Testomatio() test_run_config = TestRunConfig( + id=os.environ.get('TESTOMATIO_RUN'), title=os.environ.get('TESTOMATIO_TITLE'), group_title=os.environ.get('TESTOMATIO_RUNGROUP_TITLE'), environment=os.environ.get('TESTOMATIO_ENV'), @@ -107,7 +108,8 @@ def pytest_configure(config: Config): if project is None: pytest.exit('TESTOMATIO env variable is not set') ## TODO: move connector tin testomatio - pytest.connector = Connector(url, project) + pytest.connector = Connector(url, project) # backward compatibility + pytest.testomatio.connector = pytest.connector if config.getoption('testRunEnv'): pytest.testomatio.test_run.set_env(config.getoption('testRunEnv')) @@ -117,8 +119,7 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ meta, test_files, test_names = collect_tests(items) match config.getoption(testomatio): case 'sync': - connector: Connector = pytest.connector - connector.load_tests( + pytest.testomatio.connector.load_tests( meta, no_empty=config.getoption('no_empty'), no_detach=config.getoption('no_detach'), @@ -126,7 +127,7 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ create=config.getoption('create'), directory=config.getoption('directory') ) - testomatio_tests = connector.get_tests(meta) + testomatio_tests = pytest.testomatio.connector.get_tests(meta) add_and_enrich_tests(meta, test_files, test_names, testomatio_tests, decorator_name) pytest.exit( f'{len(items)} found. {len(meta)} unique test functions data collected and updated.' @@ -138,14 +139,16 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ pytest.exit( f'{len(items)} found. tests ids removed. Exit without test execution') case 'report': - connector: Connector = pytest.connector - test_config = pytest.testomatio.test_run - # TODO: don't create test run for shared execution - run_details = connector.create_test_run(**test_config.to_dict()) + if pytest.testomatio.test_run.id: + run_details = pytest.testomatio.connector.update_test_run(**pytest.testomatio.test_run.to_dict()) + else: + # TODO: don't create test run for shared execution + run_details = pytest.testomatio.connector.create_test_run(**pytest.testomatio.test_run.to_dict()) + pytest.testomatio.test_run.set_run_id(run_details['uid']) + if run_details is None: log.error('Test run failed to create. Reporting skipped') return - pytest.testomatio.test_run.set_run_id(run_details['uid']) if run_details.get('artifacts'): s3_access_key = os.environ.get('ACCESS_KEY_ID') or run_details['artifacts'].get('ACCESS_KEY_ID') @@ -231,12 +234,12 @@ def pytest_runtest_logfinish(nodeid, location): for nodeid, request in pytest.testomatio.test_run.status_request.items(): if request['status']: - connector = pytest.connector - connector.update_test_status(run_id=pytest.testomatio.test_run.test_run_id, **request) + pytest.testomatio.connector.update_test_status(run_id=pytest.testomatio.test_run.test_run_id, **request) pytest.testomatio.test_run.status_request = {} def pytest_sessionfinish(session: Session, exitstatus: int): + if os.environ.get('TESTOMATIO_RUN'): + return if pytest.testomatio.test_run.test_run_id: - connector = pytest.connector - connector.finish_test_run(pytest.testomatio.test_run.test_run_id) + pytest.testomatio.connector.finish_test_run(pytest.testomatio.test_run.test_run_id) diff --git a/pytestomatio/testRunConfig.py b/pytestomatio/testRunConfig.py index d65f2c5..b7acffb 100644 --- a/pytestomatio/testRunConfig.py +++ b/pytestomatio/testRunConfig.py @@ -4,6 +4,7 @@ class TestRunConfig: def __init__( self, + id: int = None, title: str = None, group_title: str = None, environment: str = None, @@ -11,7 +12,7 @@ def __init__( parallel: bool = False, shared_run: bool = False ): - self.test_run_id = None + self.test_run_id = id self.title = title if title else 'test run at ' + dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") self.environment = self.safe_string_list(environment) self.label = self.safe_string_list(label) @@ -24,6 +25,8 @@ def __init__( def to_dict(self) -> dict: result = dict() + if self.test_run_id: + result['id'] = self.test_run_id result['title'] = self.title result['group_title'] = self.group_title result['env'] = self.environment From e334dcd08826daab4d9b63b9507283d7522bb4e0 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 19:05:14 +0100 Subject: [PATCH 05/15] fix: Allow all pytest hooks execution when running sync command that run before pytest_runtestloop (actual tests) --- pytestomatio/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 3a1483c..da9374c 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -113,6 +113,10 @@ def pytest_configure(config: Config): if config.getoption('testRunEnv'): pytest.testomatio.test_run.set_env(config.getoption('testRunEnv')) +def pytest_runtestloop(session: Session): + if pytest.testomatio.session == 'sync': + print('Test sync with testomat.io finished') + pytest.exit('Exit without test execution') def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]) -> None: if config.getoption(testomatio): @@ -129,9 +133,8 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ ) testomatio_tests = pytest.testomatio.connector.get_tests(meta) add_and_enrich_tests(meta, test_files, test_names, testomatio_tests, decorator_name) - pytest.exit( - f'{len(items)} found. {len(meta)} unique test functions data collected and updated.' - f'Exit without test execution') + pytest.testomatio.session = "sync" + print(f'Found {len(items)} test. {len(meta)} unique test functions data collected and updated.') case 'remove': mapping = get_test_mapping(meta) for test_file in test_files: From f7dac3a4e755abb37d44f7c2850093ec686ff482 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 23:43:41 +0100 Subject: [PATCH 06/15] fix: Fix to check testomatio session --- pytestomatio/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index da9374c..30dc37b 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -114,9 +114,10 @@ def pytest_configure(config: Config): pytest.testomatio.test_run.set_env(config.getoption('testRunEnv')) def pytest_runtestloop(session: Session): - if pytest.testomatio.session == 'sync': - print('Test sync with testomat.io finished') - pytest.exit('Exit without test execution') + if hasattr(pytest.testomatio, 'session'): + if pytest.testomatio.session == "sync": + print('Test sync with testomat.io finished') + pytest.exit('Exit without test execution') def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]) -> None: if config.getoption(testomatio): @@ -142,7 +143,7 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ pytest.exit( f'{len(items)} found. tests ids removed. Exit without test execution') case 'report': - if pytest.testomatio.test_run.id: + if pytest.testomatio.test_run.test_run_id: run_details = pytest.testomatio.connector.update_test_run(**pytest.testomatio.test_run.to_dict()) else: # TODO: don't create test run for shared execution From 895decd68f9df5dd66865ac9f27ce7071351c7ba Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 11 Mar 2024 23:43:50 +0100 Subject: [PATCH 07/15] =?UTF-8?q?bump:=20version=202.2.0=20=E2=86=92=202.3?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 11 +++++++++++ pyproject.toml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ecdda..84fb741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 2.3.0 (2024-03-11) + +### Feat + +- Add TESTOMATIO_RUN to support test runs created on testomatio + +### Fix + +- Fix to check testomatio session +- Allow all pytest hooks execution when running sync command that run before pytest_runtestloop (actual tests) + ## 2.2.0 (2024-03-11) ### Feat diff --git a/pyproject.toml b/pyproject.toml index 7b2d88f..f6263ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.2.0" +version = "2.3.0" dependencies = [ "requests>=2.29.0", From 9001cf76d68651c5c578d0d21b23b845bd67de6e Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 13 Mar 2024 00:45:43 +0100 Subject: [PATCH 08/15] fix: Fix/workarround of the incorreclty processed parameterised test on API --- pytestomatio/testItem.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytestomatio/testItem.py b/pytestomatio/testItem.py index 74409a4..63ce0c1 100644 --- a/pytestomatio/testItem.py +++ b/pytestomatio/testItem.py @@ -129,6 +129,7 @@ def _resolve_parameter_value_in_test_name(self, item: Item, test_name: str) -> s def repl(match): key = match.group(1) + value = item.callspec.params.get(key, '') if type(value) is bytes: string_value = value.decode('utf-8') @@ -136,7 +137,8 @@ def repl(match): string_value = str(value) else: string_value = 'Unsupported type' - return string_value + # TODO: handle "value with space" on testomatio BE + return string_value.replace(" ", "_") # Temporary fix for spaces in parameter values test_name = re.sub(pattern, repl, sync_title) return test_name \ No newline at end of file From 428a798bbb8c46a594ddcb0a197f03767a52254b Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 13 Mar 2024 00:46:51 +0100 Subject: [PATCH 09/15] fix: Fix shared run reporting into new test run --- pytestomatio/connector.py | 6 +++++- pytestomatio/testRunConfig.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pytestomatio/connector.py b/pytestomatio/connector.py index 69cbb90..e9bc24f 100644 --- a/pytestomatio/connector.py +++ b/pytestomatio/connector.py @@ -2,6 +2,7 @@ from requests.exceptions import HTTPError, ConnectionError import logging from os.path import join, normpath +from os import getenv from .testItem import TestItem @@ -165,10 +166,13 @@ def update_test_status(self, run_id: str, if response.status_code == 200: log.info('Test status updated') + # TODO: I guess this class should be just an API client and used within testRun (testRunConfig) def finish_test_run(self, run_id: str) -> None: + is_parallel = getenv('TESTOMATIO_SHARED_RUN') in ['True', 'true', '1'] + status_event = "finish_parallel" if is_parallel else 'finish' try: self.session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', - json={"status_event": "finish"}) + json={"status_event": status_event}) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') return diff --git a/pytestomatio/testRunConfig.py b/pytestomatio/testRunConfig.py index b7acffb..2d562fa 100644 --- a/pytestomatio/testRunConfig.py +++ b/pytestomatio/testRunConfig.py @@ -31,7 +31,7 @@ def to_dict(self) -> dict: result['group_title'] = self.group_title result['env'] = self.environment result['label'] = self.label - result['parallel'] = self.parallel + result['parallel'] = self.shared_run # !!!! If shared run then it's parallel run in principle result['shared_run'] = self.shared_run return result From 833bfd42c79518671651c1d1a79ca6c807c3fb8c Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 13 Mar 2024 00:46:59 +0100 Subject: [PATCH 10/15] =?UTF-8?q?bump:=20version=202.3.0=20=E2=86=92=202.3?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84fb741..f4b1506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.3.1 (2024-03-13) + +### Fix + +- Fix shared run reporting into new test run +- Fix/workarround of the incorreclty processed parameterised test on API + ## 2.3.0 (2024-03-11) ### Feat diff --git a/pyproject.toml b/pyproject.toml index f6263ea..44b9832 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.3.0" +version = "2.3.1" dependencies = [ "requests>=2.29.0", From 233180b24d18efadef1acccea7d20833ecd4cec8 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 13 Mar 2024 19:08:54 +0100 Subject: [PATCH 11/15] fix: Fix dot and space in parameterised test, fix project dependency --- pyproject.toml | 3 ++- pytestomatio/testItem.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 44b9832..4339620 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "requests>=2.29.0", "pytest<8.0.0,>=7.3.1", "boto3>=1.28.28", - "libcst==1.1.0"] + "libcst==1.1.0", + "commitizen>=3.18.1"] authors = [ { name = "Oleksii Ostapov" }, diff --git a/pytestomatio/testItem.py b/pytestomatio/testItem.py index 63ce0c1..5415349 100644 --- a/pytestomatio/testItem.py +++ b/pytestomatio/testItem.py @@ -1,4 +1,4 @@ -import re +from re import sub from typing import Iterable import uuid import json @@ -137,8 +137,8 @@ def repl(match): string_value = str(value) else: string_value = 'Unsupported type' - # TODO: handle "value with space" on testomatio BE - return string_value.replace(" ", "_") # Temporary fix for spaces in parameter values + # TODO: handle "value with space" on testomatio BE https://github.com/testomatio/check-tests/issues/147 + return sub("[\.\s]", "_", string_value) # Temporary fix for spaces in parameter values - test_name = re.sub(pattern, repl, sync_title) + test_name = sub(pattern, repl, sync_title) return test_name \ No newline at end of file From 7c9c22a19926886d6a3e44dd1ae8f6fdd4b2dca0 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 13 Mar 2024 19:08:59 +0100 Subject: [PATCH 12/15] =?UTF-8?q?bump:=20version=202.3.1=20=E2=86=92=202.3?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4b1506..a4c9887 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.3.2 (2024-03-13) + +### Fix + +- Fix dot and space in parameterised test, fix project dependency + ## 2.3.1 (2024-03-13) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 4339620..3abd6e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.3.1" +version = "2.3.2" dependencies = [ "requests>=2.29.0", From 8c2e946d01488e30c07c66a06f83f0e48f17e2e4 Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 14 Mar 2024 20:18:04 +0100 Subject: [PATCH 13/15] fix TESTOMATIO_RUN parameter --- CHANGELOG.md | 30 ++++++------------------------ pytestomatio/main.py | 2 -- pytestomatio/testRunConfig.py | 2 +- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4c9887..8928a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,37 +1,19 @@ -## 2.3.2 (2024-03-13) - -### Fix - -- Fix dot and space in parameterised test, fix project dependency - -## 2.3.1 (2024-03-13) - -### Fix - -- Fix shared run reporting into new test run -- Fix/workarround of the incorreclty processed parameterised test on API - -## 2.3.0 (2024-03-11) - -### Feat - -- Add TESTOMATIO_RUN to support test runs created on testomatio - -### Fix - -- Fix to check testomatio session -- Allow all pytest hooks execution when running sync command that run before pytest_runtestloop (actual tests) - ## 2.2.0 (2024-03-11) ### Feat +- Add TESTOMATIO_RUN to support test runs created on testomatio - Add https://www.conventionalcommits.org/en/v1.0.0/ support ### Fix - Fix syncing local test with testomatio that are imported in a custom folder (on testomatio end) - Fix test run completion +- Fix to check testomatio session +- Allow all pytest hooks execution when running sync command that run before pytest_runtestloop (actual tests) +- Fix shared run reporting into new test run +- Fix/workarround of the incorreclty processed parameterised test on API +- Fix dot and space in parameterised test, fix project dependency ## 2.1.0 (2024-03-07) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 30dc37b..adf9b8b 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -243,7 +243,5 @@ def pytest_runtest_logfinish(nodeid, location): def pytest_sessionfinish(session: Session, exitstatus: int): - if os.environ.get('TESTOMATIO_RUN'): - return if pytest.testomatio.test_run.test_run_id: pytest.testomatio.connector.finish_test_run(pytest.testomatio.test_run.test_run_id) diff --git a/pytestomatio/testRunConfig.py b/pytestomatio/testRunConfig.py index 2d562fa..80fa20b 100644 --- a/pytestomatio/testRunConfig.py +++ b/pytestomatio/testRunConfig.py @@ -4,7 +4,7 @@ class TestRunConfig: def __init__( self, - id: int = None, + id: str = None, title: str = None, group_title: str = None, environment: str = None, From c0dd6928abb407fd3a88c2cbda9f1b410c064694 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 15 Mar 2024 14:19:02 +0100 Subject: [PATCH 14/15] fix: disable label and env parameters when updating test run due to 500 error from API --- .gitignore | 1 + pytestomatio/connector.py | 14 ++++++++------ pytestomatio/main.py | 1 - pytestomatio/testRunConfig.py | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f89fa9d..fe5ebc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .pytest_cache +*/**__pycache__ .idea # file for test and debug temp_test.py diff --git a/pytestomatio/connector.py b/pytestomatio/connector.py index e9bc24f..02e58e5 100644 --- a/pytestomatio/connector.py +++ b/pytestomatio/connector.py @@ -70,17 +70,18 @@ def get_tests(self, test_metadata: list[TestItem]) -> dict: def create_test_run(self, title: str, group_title, env: str, label: str, shared_run: bool, parallel) -> dict | None: request = { + "api_key": self.api_key, "title": title, "group_title": group_title, "env": env, "label": label, "parallel": parallel, - "shared_run": shared_run + "shared_run": shared_run, } filtered_request = {k: v for k, v in request.items() if v is not None} - + print('create_test_run', filtered_request) try: - response = self.session.post(f'{self.base_url}/api/reporter?api_key={self.api_key}', json=filtered_request) + response = self.session.post(f'{self.base_url}/api/reporter', json=filtered_request) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') return @@ -97,17 +98,18 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ def update_test_run(self, id: str, title: str, group_title, env: str, label: str, shared_run: bool, parallel) -> dict | None: request = { + "api_key": self.api_key, "title": title, "group_title": group_title, - "env": env, - "label": label, + #"env": env, TODO: enabled when bug with 500 response fixed + #"label": label, TODO: enabled when bug with 500 response fixed "parallel": parallel, "shared_run": shared_run } filtered_request = {k: v for k, v in request.items() if v is not None} try: - response = self.session.put(f'{self.base_url}/api/reporter/{id}?api_key={self.api_key}', json=filtered_request) + response = self.session.put(f'{self.base_url}/api/reporter/{id}', json=filtered_request) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') return diff --git a/pytestomatio/main.py b/pytestomatio/main.py index adf9b8b..3ad20e3 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -146,7 +146,6 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ if pytest.testomatio.test_run.test_run_id: run_details = pytest.testomatio.connector.update_test_run(**pytest.testomatio.test_run.to_dict()) else: - # TODO: don't create test run for shared execution run_details = pytest.testomatio.connector.create_test_run(**pytest.testomatio.test_run.to_dict()) pytest.testomatio.test_run.set_run_id(run_details['uid']) diff --git a/pytestomatio/testRunConfig.py b/pytestomatio/testRunConfig.py index 80fa20b..b39329e 100644 --- a/pytestomatio/testRunConfig.py +++ b/pytestomatio/testRunConfig.py @@ -1,4 +1,5 @@ import datetime as dt +from re import sub class TestRunConfig: @@ -31,7 +32,7 @@ def to_dict(self) -> dict: result['group_title'] = self.group_title result['env'] = self.environment result['label'] = self.label - result['parallel'] = self.shared_run # !!!! If shared run then it's parallel run in principle + result['parallel'] = self.parallel result['shared_run'] = self.shared_run return result @@ -44,4 +45,4 @@ def set_env(self, env: str) -> None: def safe_string_list(self, param: str): if not param: return None - return ",".join([part.strip() for part in param.split(',')]) + return ",".join([sub("\s", "", part) for part in param.split(',')]) From 376c1b1b7d2f2e9caf3cf9f242eb3be83ba0b6bf Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 3 Apr 2024 16:48:03 +0200 Subject: [PATCH 15/15] fix: fix regex --- README.md | 1 + pyproject.toml | 2 +- pytestomatio/testItem.py | 2 +- pytestomatio/testRunConfig.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c2d979..9f05e94 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ def test_example(): - Fix test duration - Require more back references from testomatio - pytest.skip should behave as @pytest.mark.skip +- Refactor test run and make run url available ## Contribution 1. `pip install -e .` diff --git a/pyproject.toml b/pyproject.toml index 3abd6e7..bff0401 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.3.2" +version = "2.2.0" dependencies = [ "requests>=2.29.0", diff --git a/pytestomatio/testItem.py b/pytestomatio/testItem.py index 5415349..b9655cc 100644 --- a/pytestomatio/testItem.py +++ b/pytestomatio/testItem.py @@ -138,7 +138,7 @@ def repl(match): else: string_value = 'Unsupported type' # TODO: handle "value with space" on testomatio BE https://github.com/testomatio/check-tests/issues/147 - return sub("[\.\s]", "_", string_value) # Temporary fix for spaces in parameter values + return sub(r"[\.\s]", "_", string_value) # Temporary fix for spaces in parameter values test_name = sub(pattern, repl, sync_title) return test_name \ No newline at end of file diff --git a/pytestomatio/testRunConfig.py b/pytestomatio/testRunConfig.py index b39329e..630c1ef 100644 --- a/pytestomatio/testRunConfig.py +++ b/pytestomatio/testRunConfig.py @@ -45,4 +45,4 @@ def set_env(self, env: str) -> None: def safe_string_list(self, param: str): if not param: return None - return ",".join([sub("\s", "", part) for part in param.split(',')]) + return ",".join([sub(r"\s", "", part) for part in param.split(',')])