From 7043db22c56148169e20284b91c738598760abdf Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 15 Aug 2024 23:57:43 +0200 Subject: [PATCH 01/72] fix: Parallel run must be True all the time so that testomatio doesn't create new test runs when update test status --- pytestomatio/main.py | 4 +--- pytestomatio/testomatio/testRunConfig.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 4aaf169..69e70c0 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -34,9 +34,7 @@ def pytest_configure(config: Config): if option == 'debug': return - is_parallel = config.getoption('numprocesses') is not None - - pytest.testomatio = Testomatio(TestRunConfig(is_parallel)) + pytest.testomatio = Testomatio(TestRunConfig()) url = config.getini('testomatio_url') project = os.environ.get('TESTOMATIO') diff --git a/pytestomatio/testomatio/testRunConfig.py b/pytestomatio/testomatio/testRunConfig.py index ad0e318..e9ba79d 100644 --- a/pytestomatio/testomatio/testRunConfig.py +++ b/pytestomatio/testomatio/testRunConfig.py @@ -5,7 +5,7 @@ class TestRunConfig: - def __init__(self, parallel: bool = True): + def __init__(self): self.test_run_id = os.environ.get('TESTOMATIO_RUN_ID') or None run = os.environ.get('TESTOMATIO_RUN') or None title = os.environ.get('TESTOMATIO_TITLE') or None @@ -14,7 +14,7 @@ def __init__(self, parallel: bool = True): 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') or None - self.parallel = parallel + self.parallel = True # stands for run with shards self.shared_run = run_or_title is not None self.status_request = {} From 5037f8ac03456296142f5857c78a229207d9d419 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 00:42:49 +0200 Subject: [PATCH 02/72] =?UTF-8?q?bump:=20version=202.8.1=20=E2=86=92=202.8?= =?UTF-8?q?.2.dev2?= 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 a564dbd..7c13f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.8.2.dev2 (2024-08-16) + +### Fix + +- Parallel run must be True all the time so that testomatio doesn't create new test runs when update test status + ## 2.8.1 (2024-08-14) ## 2.8.1rc2 (2024-08-12) diff --git a/pyproject.toml b/pyproject.toml index d6ebce7..139dcc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.8.1" +version = "2.8.2.dev2" dependencies = [ "requests>=2.29.0", From 1e52fcf83e90b733a584bf270d15642ae83e67a1 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 03:07:26 +0200 Subject: [PATCH 03/72] fix: Fix shared run --- pyproject.toml | 3 +-- pytestomatio/main.py | 4 ---- pytestomatio/testomatio/testRunConfig.py | 19 ++++++++++--------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 139dcc1..dd0f37f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,8 +21,7 @@ dependencies = [ "boto3>=1.28.28", "libcst==1.1.0", "commitizen>=3.18.1", - "autopep8>=2.1.0", - "pytest-xdist>=3.6.1" + "autopep8>=2.1.0" ] authors = [ diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 69e70c0..43b8065 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -11,7 +11,6 @@ from pytestomatio.utils.parser_setup import parser_options from pytestomatio.utils import helper from pytestomatio.utils import validations -from xdist.plugin import is_xdist_controller, get_xdist_worker_id log = logging.getLogger(__name__) log.setLevel('INFO') @@ -54,9 +53,6 @@ def pytest_configure(config: Config): run_details = pytest.testomatio.connector.create_test_run(**run.to_dict()) run_id = run_details.get('uid') run.save_run_id(run_id) - else: - # for xdist - worker process - do nothing - pass diff --git a/pytestomatio/testomatio/testRunConfig.py b/pytestomatio/testomatio/testRunConfig.py index e9ba79d..dbeac6a 100644 --- a/pytestomatio/testomatio/testRunConfig.py +++ b/pytestomatio/testomatio/testRunConfig.py @@ -6,17 +6,18 @@ class TestRunConfig: def __init__(self): - self.test_run_id = os.environ.get('TESTOMATIO_RUN_ID') or None - run = os.environ.get('TESTOMATIO_RUN') or None - title = os.environ.get('TESTOMATIO_TITLE') or None - run_or_title = run if run else title - self.title = run_or_title if run_or_title else 'test run at ' + dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + run_id = os.environ.get('TESTOMATIO_RUN_ID') or os.environ.get('TESTOMATIO_RUN') + title = os.environ.get('TESTOMATIO_TITLE') if os.environ.get('TESTOMATIO_TITLE') else 'test run at ' + dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + shared_run = os.environ.get('TESTOMATIO_SHARED_RUN') in ['True', 'true', '1'] + self.test_run_id = run_id + self.title = title 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') or None - self.parallel = True - # stands for run with shards - self.shared_run = run_or_title is not None + self.group_title = os.environ.get('TESTOMATIO_RUNGROUP_TITLE') + # 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. + self.shared_run = shared_run self.status_request = {} self.build_url = self.resolve_build_url() From b274ae3d991cd91e2a9f1bd1ef1f1825b01a09d6 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 03:17:11 +0200 Subject: [PATCH 04/72] =?UTF-8?q?bump:=20version=202.8.2.dev2=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 144 +++++++++++-------------------------------------- pyproject.toml | 2 +- 2 files changed, 32 insertions(+), 114 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c13f53..ca1bc8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ +## 2.8.2.dev3 (2024-08-16) + +### Fix + +- Fix shared run + ## 2.8.2.dev2 (2024-08-16) +## 2.8.2.dev1 (2024-08-16) + ### Fix - Parallel run must be True all the time so that testomatio doesn't create new test runs when update test status @@ -37,29 +45,24 @@ ## 2.6.1 (2024-08-05) -### Feat +## 2.5.0 (2024-05-08) -- Fixed report final handling with pytest-xdist -- Small code refactoring +## 2.2.0 (2024-04-03) -## 2.5.0 (2024-03-11) +### Fix -### Feat +- fix regex +- disable label and env parameters when updating test run due to 500 error from API +- Fix dot and space in parameterised test, fix project dependency -- Plugin code refactored -- Introduced ENV variable `TESTOMATIO_CODE_STYLE` to select code style formating **PEP8** or don't format at all -- Updated pytest version supported to 8+ -- Set parallel run as default parameter. ENV variable `TESTOMATIO_SHARED_RUN` is not needed -- Introduced sync lock to be used with pytest-xdist. Env variable `TESTOMATIO_TITLE` becomes optional +## 2.3.1 (2024-03-13) ### Fix -- Fixed NPE when some params not set -- Fixed pytest exception with using **xdist** lib -- Fixed test parameters transfer for DDT tests - +- Fix shared run reporting into new test run +- Fix/workarround of the incorreclty processed parameterised test on API -## 2.2.0 (2024-03-11) +## 2.3.0 (2024-03-11) ### Feat @@ -68,119 +71,34 @@ ### 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 +- Fix syncing local test with testomatio that are imported in a custom folder (on testomatio end) ## 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.7.0 (2024-02-26) +## 1.6.0 (2024-02-21) -### 1.5.0 (2024-02-12) +## 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) -### 1.4.0 (2024-02-06) +## 1.3.0 (2023-12-06) -### Feat +## 1.2.8 (2023-12-06) -- 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.2.5 (2023-10-21) -### 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.2.4 (2023-09-05) -### 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 +## 1.2.3 (2023-09-03) -- [issue 4](https://github.com/Ypurek/pytest-analyzer/issues/4) - Analyzer's execution order +## 1.2.0 (2023-08-20) -### 1.2.5 (2023-10-21) +## 1.1.1 (2023-08-17) -### 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 +## 1.0.9 (2023-07-31) diff --git a/pyproject.toml b/pyproject.toml index dd0f37f..92c9e00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.8.2.dev2" +version = "2.8.2.dev3" dependencies = [ "requests>=2.29.0", From 2889f5dcf525f5159c66debb6fa8d668b73fe251 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 03:48:50 +0200 Subject: [PATCH 05/72] fix: Fix option check --- pytestomatio/utils/validations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytestomatio/utils/validations.py b/pytestomatio/utils/validations.py index fe11618..03027aa 100644 --- a/pytestomatio/utils/validations.py +++ b/pytestomatio/utils/validations.py @@ -10,7 +10,7 @@ def validate_option(config: Config) -> Literal['sync', 'report', 'remove', 'debu if os.getenv('TESTOMATIO') is None: raise ValueError('TESTOMATIO env variable is not set') - if config.getoption('numprocesses') and option in ('sync', 'debug', 'remove'): + if hasattr(config.option, 'numprocesses') and option in ('sync', 'debug', 'remove'): raise ValueError('Testomatio does not support parallel sync, remove or report. Remove --numprocesses option') return option From 8378a176b840207b9559bf07f96ed6da789fb0f0 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 03:52:36 +0200 Subject: [PATCH 06/72] build: update deps --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 92c9e00..cb96ee6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "pytest>7.2.0", "boto3>=1.28.28", "libcst==1.1.0", - "commitizen>=3.18.1", + "commitizen>=3.29.0", "autopep8>=2.1.0" ] From 80614ccf0d5aece5f92d059a11c32f70f7723191 Mon Sep 17 00:00:00 2001 From: Tiko Date: Fri, 16 Aug 2024 03:53:49 +0200 Subject: [PATCH 07/72] =?UTF-8?q?bump:=20version=202.8.2.dev3=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev4?= 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 ca1bc8a..974f8a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.8.2.dev4 (2024-08-16) + +### Fix + +- Fix option check + ## 2.8.2.dev3 (2024-08-16) ### Fix diff --git a/pyproject.toml b/pyproject.toml index cb96ee6..dfbb87e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = true [project] name = "pytestomatio" -version = "2.8.2.dev3" +version = "2.8.2.dev4" dependencies = [ "requests>=2.29.0", From 0b3c107dead391367c96e3e9770be8a8d1174f67 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sat, 24 Aug 2024 10:41:13 +0200 Subject: [PATCH 08/72] feat: support HTTP_PROXY var --- pytestomatio/connect/connector.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 781d156..12089d1 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -17,6 +17,13 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.jwt: str = '' self.api_key = api_key + if getenv('HTTP_PROXY'): + self.session.proxies = { + 'http': getenv('HTTP_PROXY'), + 'https': getenv('HTTP_PROXY') + } + self.session.verify = False + def load_tests( self, tests: list[TestItem], From c053e04ac2a9cc1a89352499c7163177347ae221 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sat, 24 Aug 2024 10:57:43 +0200 Subject: [PATCH 09/72] fix: Fix shared runs --- pytestomatio/connect/connector.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 12089d1..a57f724 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -86,6 +86,7 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ "label": label, "parallel": parallel, "ci_build_url": ci_build_url, + "shared_run": shared_run } filtered_request = {k: v for k, v in request.items() if v is not None} try: From 7ebcb989d1d3602b139ccc6b5c2ab364fc50df5e Mon Sep 17 00:00:00 2001 From: Tiko Date: Sat, 24 Aug 2024 11:11:27 +0200 Subject: [PATCH 10/72] refactor: Use system temp folder --- pytestomatio/testomatio/testRunConfig.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pytestomatio/testomatio/testRunConfig.py b/pytestomatio/testomatio/testRunConfig.py index dbeac6a..b58421f 100644 --- a/pytestomatio/testomatio/testRunConfig.py +++ b/pytestomatio/testomatio/testRunConfig.py @@ -1,8 +1,10 @@ import os import datetime as dt +import tempfile from pytestomatio.utils.helper import safe_string_list from typing import Optional +TESTOMATIO_TEST_RUN_LOCK_FILE = ".testomatio_test_run_id_lock" class TestRunConfig: def __init__(self): @@ -39,21 +41,28 @@ def set_env(self, env: str) -> None: def save_run_id(self, run_id: str) -> None: self.test_run_id = run_id - with open('.temp_test_run_id', 'w') as f: + temp_dir = tempfile.gettempdir() + temp_file_path = os.path.join(temp_dir, TESTOMATIO_TEST_RUN_LOCK_FILE) + with open(temp_file_path, 'w') as f: f.write(run_id) + def get_run_id(self) -> Optional[str]: if self.test_run_id: return self.test_run_id - if os.path.exists('.temp_test_run_id'): - with open('.temp_test_run_id', 'r') as f: + temp_dir = tempfile.gettempdir() + temp_file_path = os.path.join(temp_dir, TESTOMATIO_TEST_RUN_LOCK_FILE) + if os.path.exists(temp_file_path): + with open(temp_file_path, 'r') as f: self.test_run_id = f.read() return self.test_run_id return None def clear_run_id(self) -> None: - if os.path.exists('.temp_test_run_id'): - os.remove('.temp_test_run_id') + temp_dir = tempfile.gettempdir() + temp_file_path = os.path.join(temp_dir, TESTOMATIO_TEST_RUN_LOCK_FILE) + if os.path.exists(temp_file_path): + os.remove(temp_file_path) def resolve_build_url(self) -> Optional[str]: # You might not always want the build URL to change in the Testomat.io test run From f6b41a3445b02f43b4f44ff80269b474adff2ffb Mon Sep 17 00:00:00 2001 From: Tiko Date: Sat, 24 Aug 2024 11:43:05 +0200 Subject: [PATCH 11/72] =?UTF-8?q?bump:=20version=202.8.2.dev4=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dfbb87e..06e210e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,10 +10,10 @@ name = "cz_conventional_commits" tag_format = "$version" version_scheme = "pep440" version_provider = "pep621" -update_changelog_on_bump = true +update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev4" +version = "2.8.2.dev5" dependencies = [ "requests>=2.29.0", From c5c61eab542feb94d07742ca457316bb256bbf28 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sat, 24 Aug 2024 11:45:14 +0200 Subject: [PATCH 12/72] docs: update changelog --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 974f8a7..13d5c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 2.8.2.dev5 (2024-08-24) + +### Feat + +- support HTTP_PROXY var + +### Fix + +- Fix shared runs + +### Refactor + +- Use system temp folder + ## 2.8.2.dev4 (2024-08-16) ### Fix From cf6d83bac8dd521bc5a50caae717b1f21e8e8de7 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 14:05:32 +0200 Subject: [PATCH 13/72] feat: send lables and tags on the test run update call --- pytestomatio/connect/connector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index a57f724..e9b393d 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -111,10 +111,11 @@ def update_test_run(self, id: str, title: str, group_title, "api_key": self.api_key, "title": title, "group_title": group_title, - # "env": env, TODO: enabled when bug with 500 response fixed - # "label": label, TODO: enabled when bug with 500 response fixed + "env": env, + "label": label, "parallel": parallel, "ci_build_url": ci_build_url, + "shared_run": shared_run } filtered_request = {k: v for k, v in request.items() if v is not None} From 8fea9fbbb0e9e3606f09362f26e9f482488e8459 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 14:06:26 +0200 Subject: [PATCH 14/72] =?UTF-8?q?bump:=20version=202.8.2.dev5=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 06e210e..a07ec17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev5" +version = "2.8.2.dev6" dependencies = [ "requests>=2.29.0", From 58b8f8f94af709e7f85c85596a68b13ae9c434ec Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 16:21:03 +0200 Subject: [PATCH 15/72] feat: do not rely on @T in test id, it's optional part, but still accept such test ids. ex. @T322453 -> 322453 --- pytestomatio/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 43b8065..e15eca1 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -61,19 +61,19 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ if config.getoption(testomatio) is None: return - # Filter by --test-ids if provided + # Filter by --test-id if provided test_ids_option = config.getoption("test_id") if test_ids_option: test_ids = test_ids_option.split("|") # Remove "@" from the start of test IDs if present - test_ids = [test_id.lstrip("@") for test_id in test_ids] + test_ids = [test_id.lstrip("@T") for test_id in test_ids] selected_items = [] deselected_items = [] for item in items: # Check if the test has the marker with the ID we are looking for for marker in item.iter_markers(name="testomatio"): - marker_id = marker.args[0].strip("@") # Strip "@" from the marker argument + marker_id = marker.args[0].lstrip("@T") # Strip "@" from the marker argument if marker_id in test_ids: selected_items.append(item) break From c6a084e0ec70d522a7de033f6227486fb94769af Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 16:21:29 +0200 Subject: [PATCH 16/72] =?UTF-8?q?bump:=20version=202.8.2.dev6=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a07ec17..d4fa915 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev6" +version = "2.8.2.dev7" dependencies = [ "requests>=2.29.0", From 514a3546dc99ddbaff730eaab24e238b512977d3 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 17:51:04 +0200 Subject: [PATCH 17/72] fix: log error message on test run update failure --- pytestomatio/connect/connector.py | 10 +++++----- pytestomatio/main.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index e9b393d..355c47a 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -121,14 +121,14 @@ def update_test_run(self, id: str, title: str, group_title, try: 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}') + except ConnectionError as ce: + log.error(f'Failed to connect to {self.base_url}: {ce}') return - except HTTPError: - log.error(f'Failed to connect to {self.base_url}') + except HTTPError as he: + log.error(f'Failed to connect to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue. {e}') + log.error(f'Generic exception happened. Please report an issue: {e}') return if response.status_code == 200: diff --git a/pytestomatio/main.py b/pytestomatio/main.py index e15eca1..36cb53a 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -111,7 +111,8 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ run_details = pytest.testomatio.connector.update_test_run(**run.to_dict()) if run_details is None: - raise Exception('Test run failed to create. Reporting skipped') + log.error('Test run failed to create. Reporting skipped') + return artifact = run_details.get('artifacts') if artifact: From 00a9da8ffdd55a422680612485fe36c5c218ab54 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 25 Aug 2024 17:52:17 +0200 Subject: [PATCH 18/72] =?UTF-8?q?bump:=20version=202.8.2.dev7=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d4fa915..03db95c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev7" +version = "2.8.2.dev8" dependencies = [ "requests>=2.29.0", From 72a522ae6b8ceea02c558216b12c2f05dc0eb0fd Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 11:21:30 +0200 Subject: [PATCH 19/72] fix: read S3 creads from env acc to the testomatio docs --- README.md | 2 ++ pytestomatio/connect/s3_connector.py | 23 +++++++++++++++-------- pytestomatio/utils/helper.py | 9 +++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 00bc20d..ce503ad 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,8 @@ def test_example(): - test run labels, tags ## TODO +- retry test run update with less attributes, we get 500 from api +- handler non configured s3 bucket error - Fix test duration ## Contribution diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index 47cef1a..f3e684f 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -1,3 +1,4 @@ +from typing import Optional import boto3 import logging from io import BytesIO @@ -6,7 +7,7 @@ log.setLevel('INFO') -def parse_endpoint(endpoint: str or None) -> str or None: +def parse_endpoint(endpoint: str = None) -> Optional[str]: if endpoint is None: return if endpoint.startswith('https://'): @@ -17,11 +18,14 @@ def parse_endpoint(endpoint: str or None) -> str or None: class S3Connector: - def __init__(self, aws_access_key_id: str or None = None, - aws_secret_access_key: str or None = None, - endpoint: str or None = None, - bucket_name: str or None = None): + def __init__(self, + aws_region_name: Optional[str], + aws_access_key_id: Optional[str], + aws_secret_access_key: Optional[str], + endpoint: Optional[str], + bucket_name: Optional[str]): + self.aws_region_name = aws_region_name self.endpoint = parse_endpoint(endpoint) self.bucket_name = bucket_name self.client = None @@ -35,11 +39,14 @@ def login(self): 's3', endpoint_url=f'https://{self.endpoint}', aws_access_key_id=self.aws_access_key_id, - aws_secret_access_key=self.aws_secret_access_key) + aws_secret_access_key=self.aws_secret_access_key, + region_name=self.aws_region_name + ), + self._is_logged_in = True log.info('s3 session created') - def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) -> str or None: + def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) -> Optional[str]: if not self._is_logged_in: log.warning('s3 session is not created, creating new one') return @@ -54,7 +61,7 @@ def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') return f'https://{bucket_name}.{self.endpoint}/{key}' - def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = None) -> str or None: + def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = None) -> Optional[str]: if not self._is_logged_in: log.warning('s3 session is not created, creating new one') return diff --git a/pytestomatio/utils/helper.py b/pytestomatio/utils/helper.py index 65c67af..e598e40 100644 --- a/pytestomatio/utils/helper.py +++ b/pytestomatio/utils/helper.py @@ -86,10 +86,11 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, def read_env_s3_keys(artifact: dict) -> tuple: return ( - os.environ.get('ACCESS_KEY_ID') or artifact.get('ACCESS_KEY_ID'), - os.environ.get('SECRET_ACCESS_KEY') or artifact.get('SECRET_ACCESS_KEY'), - os.environ.get('ENDPOINT') or artifact.get('ENDPOINT'), - os.environ.get('BUCKET') or artifact.get('BUCKET') + os.environ.get('REGION') or os.environ.get('S3_REGION') or artifact.get('REGION'), + os.environ.get('ACCESS_KEY_ID') or os.environ.get('S3_ACCESS_KEY_ID') or artifact.get('ACCESS_KEY_ID'), + os.environ.get('SECRET_ACCESS_KEY') or os.environ.get('S3_SECRET_ACCESS_KEY') or artifact.get('SECRET_ACCESS_KEY'), + os.environ.get('ENDPOINT') or os.environ.get('S3_ENDPOINT') or artifact.get('ENDPOINT'), + os.environ.get('BUCKET') or os.environ.get('S3_BUCKET') or artifact.get('BUCKET') ) def safe_string_list(param: str): From 1aa8772348322d8b2729f0f16d054812c0956dc6 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 11:21:50 +0200 Subject: [PATCH 20/72] =?UTF-8?q?bump:=20version=202.8.2.dev8=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 03db95c..3be388c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev8" +version = "2.8.2.dev9" dependencies = [ "requests>=2.29.0", From 775a4bfd67b30c119c75399d43a625f21e7f5f8d Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:26:16 +0200 Subject: [PATCH 21/72] fix: Fix uploading artifacts to the bucket with user defined path --- README.md | 2 +- pytestomatio/connect/s3_connector.py | 18 ++++++++++-------- pytestomatio/main.py | 17 ++++++++--------- pytestomatio/utils/helper.py | 15 +++++++++------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ce503ad..60f5918 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ https://docs.testomat.io/usage/test-artifacts/ Analyser needs to be aware of the cloud storage credentials. There are two options: 1. Enable **Share credentials with testomat.io Reporter** option in testomat.io Settings -> Artifacts. -2. Use environment variables `ACCESS_KEY_ID, SECRET_ACCESS_KEY, ENDPOINT, BUCKET` +2. Use environment variables `ACCESS_KEY_ID, SECRET_ACCESS_KEY, ENDPOINT, BUCKET, BUCKET_PATH` You would need to decide when you want to upload your test artifacts to cloud storage diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index f3e684f..5e938f5 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -16,18 +16,20 @@ def parse_endpoint(endpoint: str = None) -> Optional[str]: return endpoint[7:] return endpoint - class S3Connector: def __init__(self, aws_region_name: Optional[str], aws_access_key_id: Optional[str], aws_secret_access_key: Optional[str], endpoint: Optional[str], - bucket_name: Optional[str]): + bucket_name: Optional[str], + bucker_prefix: Optional[str] + ): self.aws_region_name = aws_region_name self.endpoint = parse_endpoint(endpoint) self.bucket_name = bucket_name + self.bucker_prefix = bucker_prefix self.client = None self._is_logged_in = False self.aws_access_key_id = aws_access_key_id @@ -41,7 +43,7 @@ def login(self): aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, region_name=self.aws_region_name - ), + ) self._is_logged_in = True log.info('s3 session created') @@ -52,10 +54,10 @@ def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) return if not key: key = file_path + key = f"{self.bucker_prefix}/{key}" if not bucket_name: bucket_name = self.bucket_name - if bucket_name is None: - raise Exception('bucket name is not defined') + log.info(f'uploading artifact {file_path} to s3://{bucket_name}/{key}') self.client.upload_file(file_path, bucket_name, key) log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') @@ -68,9 +70,9 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non file = BytesIO(file_bytes) if not bucket_name: bucket_name = self.bucket_name - if bucket_name is None: - raise Exception('bucket name is not defined') + key = f"{self.bucker_prefix}/{key}" + log.info(f'uploading artifact {key} to s3://{bucket_name}/{key}') self.client.upload_fileobj(file, bucket_name, key) log.info(f'artifact {key} uploaded to s3://{bucket_name}/{key}') - return f'https://{bucket_name}.{self.endpoint}/{key}' + return f'https://{bucket_name}.{self.endpoint}/{key}' diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 36cb53a..52d3939 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -114,15 +114,14 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ log.error('Test run failed to create. Reporting skipped') return - artifact = run_details.get('artifacts') - if artifact: - s3_details = helper.read_env_s3_keys(artifact) - - if all(s3_details): - pytest.testomatio.s3_connector = S3Connector(*s3_details) - pytest.testomatio.s3_connector.login() - else: - pytest.testomatio.s3_connector = S3Connector() + s3_details = helper.read_env_s3_keys(run_details) + + if all(s3_details): + pytest.testomatio.s3_connector = S3Connector(*s3_details) + pytest.testomatio.s3_connector.login() + else: + pytest.testomatio.s3_connector = S3Connector() + case 'debug': with open(metadata_file, 'w') as file: data = json.dumps([i.to_dict() for i in meta], indent=4) diff --git a/pytestomatio/utils/helper.py b/pytestomatio/utils/helper.py index e598e40..b5e9cb5 100644 --- a/pytestomatio/utils/helper.py +++ b/pytestomatio/utils/helper.py @@ -84,13 +84,16 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, update_tests(test_file, mapping, test_names, decorator_name) -def read_env_s3_keys(artifact: dict) -> tuple: +def read_env_s3_keys(testRunConfig: dict) -> tuple: + artifacts = testRunConfig.get('artifacts') + bucket_path = (os.environ.get('BUCKET_PATH') or os.environ.get('S3_BUCKET_PATH')) return ( - os.environ.get('REGION') or os.environ.get('S3_REGION') or artifact.get('REGION'), - os.environ.get('ACCESS_KEY_ID') or os.environ.get('S3_ACCESS_KEY_ID') or artifact.get('ACCESS_KEY_ID'), - os.environ.get('SECRET_ACCESS_KEY') or os.environ.get('S3_SECRET_ACCESS_KEY') or artifact.get('SECRET_ACCESS_KEY'), - os.environ.get('ENDPOINT') or os.environ.get('S3_ENDPOINT') or artifact.get('ENDPOINT'), - os.environ.get('BUCKET') or os.environ.get('S3_BUCKET') or artifact.get('BUCKET') + os.environ.get('REGION') or os.environ.get('S3_REGION') or artifacts.get('REGION'), + os.environ.get('ACCESS_KEY_ID') or os.environ.get('S3_ACCESS_KEY_ID') or artifacts.get('ACCESS_KEY_ID'), + os.environ.get('SECRET_ACCESS_KEY') or os.environ.get('S3_SECRET_ACCESS_KEY') or artifacts.get('SECRET_ACCESS_KEY'), + os.environ.get('ENDPOINT') or os.environ.get('S3_ENDPOINT') or artifacts.get('ENDPOINT'), + os.environ.get('BUCKET') or os.environ.get('S3_BUCKET') or artifacts.get('BUCKET'), + bucket_path + "/" + testRunConfig.get("uid") if bucket_path else testRunConfig.get("uid") ) def safe_string_list(param: str): From b6d9fbff5bc31138eb85a6945218c6a519c525a1 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:26:26 +0200 Subject: [PATCH 22/72] =?UTF-8?q?bump:=20version=202.8.2.dev9=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3be388c..628eceb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev9" +version = "2.8.2.dev10" dependencies = [ "requests>=2.29.0", From 10b64a1724e556809b7030d9760a49e1f058ea69 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:46:09 +0200 Subject: [PATCH 23/72] fix: fix get env --- pytestomatio/utils/helper.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pytestomatio/utils/helper.py b/pytestomatio/utils/helper.py index b5e9cb5..1ffae85 100644 --- a/pytestomatio/utils/helper.py +++ b/pytestomatio/utils/helper.py @@ -1,4 +1,4 @@ -import os +from os import getenv from os.path import basename from pytest import Item from pytestomatio.testomatio.testomat_item import TestomatItem @@ -86,13 +86,13 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, def read_env_s3_keys(testRunConfig: dict) -> tuple: artifacts = testRunConfig.get('artifacts') - bucket_path = (os.environ.get('BUCKET_PATH') or os.environ.get('S3_BUCKET_PATH')) + bucket_path = (getenv('BUCKET_PATH') or getenv('S3_BUCKET_PATH')) return ( - os.environ.get('REGION') or os.environ.get('S3_REGION') or artifacts.get('REGION'), - os.environ.get('ACCESS_KEY_ID') or os.environ.get('S3_ACCESS_KEY_ID') or artifacts.get('ACCESS_KEY_ID'), - os.environ.get('SECRET_ACCESS_KEY') or os.environ.get('S3_SECRET_ACCESS_KEY') or artifacts.get('SECRET_ACCESS_KEY'), - os.environ.get('ENDPOINT') or os.environ.get('S3_ENDPOINT') or artifacts.get('ENDPOINT'), - os.environ.get('BUCKET') or os.environ.get('S3_BUCKET') or artifacts.get('BUCKET'), + getenv('REGION') or getenv('S3_REGION') or artifacts.get('REGION'), + getenv('ACCESS_KEY_ID') or getenv('S3_ACCESS_KEY_ID') or artifacts.get('ACCESS_KEY_ID'), + getenv('SECRET_ACCESS_KEY') or getenv('S3_SECRET_ACCESS_KEY') or artifacts.get('SECRET_ACCESS_KEY'), + getenv('ENDPOINT') or getenv('S3_ENDPOINT') or artifacts.get('ENDPOINT'), + getenv('BUCKET') or getenv('S3_BUCKET') or artifacts.get('BUCKET'), bucket_path + "/" + testRunConfig.get("uid") if bucket_path else testRunConfig.get("uid") ) From b552fd65ea27c91671eb5e7f8ff395a871801c50 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:46:14 +0200 Subject: [PATCH 24/72] =?UTF-8?q?bump:=20version=202.8.2.dev10=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 628eceb..f330cdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev10" +version = "2.8.2.dev11" dependencies = [ "requests>=2.29.0", From f43f77e41082aabf3eb136b48a683c5eddcafb75 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:55:20 +0200 Subject: [PATCH 25/72] fix: empty dict --- pytestomatio/utils/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytestomatio/utils/helper.py b/pytestomatio/utils/helper.py index 1ffae85..eb8f91f 100644 --- a/pytestomatio/utils/helper.py +++ b/pytestomatio/utils/helper.py @@ -85,7 +85,7 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, def read_env_s3_keys(testRunConfig: dict) -> tuple: - artifacts = testRunConfig.get('artifacts') + artifacts = testRunConfig.get('artifacts', {}) bucket_path = (getenv('BUCKET_PATH') or getenv('S3_BUCKET_PATH')) return ( getenv('REGION') or getenv('S3_REGION') or artifacts.get('REGION'), From a088ef48683401bc65b897db322c3750ae7d8775 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 27 Aug 2024 20:55:24 +0200 Subject: [PATCH 26/72] =?UTF-8?q?bump:=20version=202.8.2.dev11=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f330cdc..347ba4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev11" +version = "2.8.2.dev12" dependencies = [ "requests>=2.29.0", From ab30eb4572b15456e12f9bc6c073f89062ac72b8 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 28 Aug 2024 19:53:03 +0200 Subject: [PATCH 27/72] feat: support private and public artifact configuration --- pytestomatio/connect/s3_connector.py | 8 +++++--- pytestomatio/main.py | 1 + pytestomatio/utils/helper.py | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index 5e938f5..e84c844 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -23,7 +23,8 @@ def __init__(self, aws_secret_access_key: Optional[str], endpoint: Optional[str], bucket_name: Optional[str], - bucker_prefix: Optional[str] + bucker_prefix: Optional[str], + acl: Optional[str] = 'public-read' ): self.aws_region_name = aws_region_name @@ -34,6 +35,7 @@ def __init__(self, self._is_logged_in = False self.aws_access_key_id = aws_access_key_id self.aws_secret_access_key = aws_secret_access_key + self.acl = acl def login(self): log.debug('creating s3 session') @@ -59,7 +61,7 @@ def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) bucket_name = self.bucket_name log.info(f'uploading artifact {file_path} to s3://{bucket_name}/{key}') - self.client.upload_file(file_path, bucket_name, key) + self.client.upload_file(file_path, bucket_name, key, ExtraArgs={'ACL': self.acl}) log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') return f'https://{bucket_name}.{self.endpoint}/{key}' @@ -73,6 +75,6 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non key = f"{self.bucker_prefix}/{key}" log.info(f'uploading artifact {key} to s3://{bucket_name}/{key}') - self.client.upload_fileobj(file, bucket_name, key) + self.client.upload_fileobj(file, bucket_name, key, ExtraArgs={'ACL': self.acl}) log.info(f'artifact {key} uploaded to s3://{bucket_name}/{key}') return f'https://{bucket_name}.{self.endpoint}/{key}' diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 52d3939..2a4ee83 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -120,6 +120,7 @@ def pytest_collection_modifyitems(session: Session, config: Config, items: list[ pytest.testomatio.s3_connector = S3Connector(*s3_details) pytest.testomatio.s3_connector.login() else: + # TODO: handle missing credentials pytest.testomatio.s3_connector = S3Connector() case 'debug': diff --git a/pytestomatio/utils/helper.py b/pytestomatio/utils/helper.py index eb8f91f..7010659 100644 --- a/pytestomatio/utils/helper.py +++ b/pytestomatio/utils/helper.py @@ -87,13 +87,15 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set, def read_env_s3_keys(testRunConfig: dict) -> tuple: artifacts = testRunConfig.get('artifacts', {}) bucket_path = (getenv('BUCKET_PATH') or getenv('S3_BUCKET_PATH')) + acl = 'private' if (getenv('TESTOMATIO_PRIVATE_ARTIFACTS') or artifacts.get('presign')) else "public-read" return ( getenv('REGION') or getenv('S3_REGION') or artifacts.get('REGION'), getenv('ACCESS_KEY_ID') or getenv('S3_ACCESS_KEY_ID') or artifacts.get('ACCESS_KEY_ID'), getenv('SECRET_ACCESS_KEY') or getenv('S3_SECRET_ACCESS_KEY') or artifacts.get('SECRET_ACCESS_KEY'), getenv('ENDPOINT') or getenv('S3_ENDPOINT') or artifacts.get('ENDPOINT'), getenv('BUCKET') or getenv('S3_BUCKET') or artifacts.get('BUCKET'), - bucket_path + "/" + testRunConfig.get("uid") if bucket_path else testRunConfig.get("uid") + bucket_path + "/" + testRunConfig.get("uid") if bucket_path else testRunConfig.get("uid"), + acl ) def safe_string_list(param: str): From 416d8b4700c709e864ee0bea0718f06262142360 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 28 Aug 2024 19:53:23 +0200 Subject: [PATCH 28/72] =?UTF-8?q?bump:=20version=202.8.2.dev12=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 347ba4f..54e9f45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev12" +version = "2.8.2.dev13" dependencies = [ "requests>=2.29.0", From 8eee6dc12b1ac7b55c9c1f354444d4bdb7842372 Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 1 Sep 2024 23:23:32 +0200 Subject: [PATCH 29/72] feat: resolve content type for uploaded artifacts --- pytestomatio/connect/s3_connector.py | 33 +++++++++++++++++++-------- pytestomatio/testomatio/testomatio.py | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index e84c844..31b824f 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -2,14 +2,13 @@ import boto3 import logging from io import BytesIO +import mimetypes log = logging.getLogger(__name__) log.setLevel('INFO') def parse_endpoint(endpoint: str = None) -> Optional[str]: - if endpoint is None: - return if endpoint.startswith('https://'): return endpoint[8:] elif endpoint.startswith('http://'): @@ -60,10 +59,17 @@ def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) if not bucket_name: bucket_name = self.bucket_name - log.info(f'uploading artifact {file_path} to s3://{bucket_name}/{key}') - self.client.upload_file(file_path, bucket_name, key, ExtraArgs={'ACL': self.acl}) - log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') - return f'https://{bucket_name}.{self.endpoint}/{key}' + content_type, _ = mimetypes.guess_type(key) + if content_type is None: + content_type = 'application/octet-stream' + + try: + log.info(f'uploading artifact {file_path} to s3://{bucket_name}/{key}') + self.client.upload_file(file_path, bucket_name, key, ExtraArgs={'ACL': self.acl, 'ContentType': content_type}) + log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') + return f'https://{bucket_name}.{self.endpoint}/{key}' + except Exception as e: + log.error(f'failed to upload file {file_path} to s3://{bucket_name}/{key}: {e}') def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = None) -> Optional[str]: if not self._is_logged_in: @@ -74,7 +80,14 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non bucket_name = self.bucket_name key = f"{self.bucker_prefix}/{key}" - log.info(f'uploading artifact {key} to s3://{bucket_name}/{key}') - self.client.upload_fileobj(file, bucket_name, key, ExtraArgs={'ACL': self.acl}) - log.info(f'artifact {key} uploaded to s3://{bucket_name}/{key}') - return f'https://{bucket_name}.{self.endpoint}/{key}' + content_type, _ = mimetypes.guess_type(key) + if content_type is None: + content_type = 'application/octet-stream' + + try: + log.info(f'uploading artifact {key} to s3://{bucket_name}/{key}') + self.client.upload_fileobj(file, bucket_name, key, ExtraArgs={'ACL': self.acl, 'ContentType': content_type}) + log.info(f'artifact {key} uploaded to s3://{bucket_name}/{key}') + return f'https://{bucket_name}.{self.endpoint}/{key}' + except Exception as e: + log.error(f'failed to upload file {key} to s3://{bucket_name}/{key}: {e}') diff --git a/pytestomatio/testomatio/testomatio.py b/pytestomatio/testomatio/testomatio.py index 551cc84..68552dd 100644 --- a/pytestomatio/testomatio/testomatio.py +++ b/pytestomatio/testomatio/testomatio.py @@ -26,4 +26,4 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non def add_artifacts(self, node: Function, urls: list[str]) -> None: artifact_urls = node.stash.get("artifact_urls", []) artifact_urls.extend(urls) - node.stash["artifact_urls"] = artifact_urls + node.stash["artifact_urls"] = [ url for url in artifact_urls if url is not None] From 7800768b04aa2260caf0336fc8fbe971d737ee2b Mon Sep 17 00:00:00 2001 From: Tiko Date: Sun, 1 Sep 2024 23:24:21 +0200 Subject: [PATCH 30/72] =?UTF-8?q?bump:=20version=202.8.2.dev13=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 54e9f45..d22c0e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev13" +version = "2.8.2.dev14" dependencies = [ "requests>=2.29.0", From f754f7b1584b3e2b1924ef0dfa7fcdbb74fb0def Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:21:09 +0200 Subject: [PATCH 31/72] fix: resolve proxy for entire session duration --- pytestomatio/connect/connector.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 355c47a..b2c40eb 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -17,10 +17,19 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.jwt: str = '' self.api_key = api_key - if getenv('HTTP_PROXY'): + def __getattribute__(self, name): + if name == "session": + self._proxy_resolve() + return self.session + return super().__getattribute__(name) + + + def _proxy_resolve(self): + http_proxy = getenv('HTTP_PROXY') + if http_proxy: self.session.proxies = { - 'http': getenv('HTTP_PROXY'), - 'https': getenv('HTTP_PROXY') + 'http': http_proxy, + 'https': http_proxy } self.session.verify = False From 9e03dcbac91824915385fb0fc40ee9cc85708761 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:21:13 +0200 Subject: [PATCH 32/72] =?UTF-8?q?bump:=20version=202.8.2.dev14=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d22c0e4..fca5e22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev14" +version = "2.8.2.dev15" dependencies = [ "requests>=2.29.0", From 99490a9ca0fef21dcef135129d5a32c8ae1edb8c Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:34:52 +0200 Subject: [PATCH 33/72] fix: fix infinitive loop --- pytestomatio/connect/connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index b2c40eb..9fad6a8 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -20,7 +20,7 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non def __getattribute__(self, name): if name == "session": self._proxy_resolve() - return self.session + return super().__getattribute__('session') return super().__getattribute__(name) From 5648f6b60e92f81da78023e161533968441df60a Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:34:55 +0200 Subject: [PATCH 34/72] =?UTF-8?q?bump:=20version=202.8.2.dev15=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fca5e22..0a82484 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev15" +version = "2.8.2.dev16" dependencies = [ "requests>=2.29.0", From 9b5709a4f84325ffed784228d7c92a3a487df3b2 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:45:46 +0200 Subject: [PATCH 35/72] fix: recursion must not happen --- pytestomatio/connect/connector.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 9fad6a8..e175a14 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -20,18 +20,19 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non def __getattribute__(self, name): if name == "session": self._proxy_resolve() - return super().__getattribute__('session') + return super().__getattribute__('__dict__')['session'] return super().__getattribute__(name) def _proxy_resolve(self): http_proxy = getenv('HTTP_PROXY') if http_proxy: - self.session.proxies = { + session = super().__getattribute__('__dict__')['session'] + session.proxies = { 'http': http_proxy, 'https': http_proxy } - self.session.verify = False + session.verify = False def load_tests( self, From ea2f10c0670754580025e67b1c4ba991ce950a81 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 01:45:52 +0200 Subject: [PATCH 36/72] =?UTF-8?q?bump:=20version=202.8.2.dev16=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0a82484..38eb978 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev16" +version = "2.8.2.dev17" dependencies = [ "requests>=2.29.0", From aaeb290df5c5242a3f6a512e64018028926e704e Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 09:29:14 +0200 Subject: [PATCH 37/72] fix: fix proxy once again --- pytestomatio/connect/connector.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index e175a14..b01e0b7 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -16,24 +16,21 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.session.verify = True self.jwt: str = '' self.api_key = api_key + self._proxy_resolve() - def __getattribute__(self, name): + def _proxy_resolve(self): + http_proxy = getenv("HTTP_PROXY") + if http_proxy: + self.session.proxies = {"http": http_proxy, "https": http_proxy} + self.session.verify = False + else: + self.session.verify = True + + def __getattribute__(self, name: str): if name == "session": self._proxy_resolve() - return super().__getattribute__('__dict__')['session'] return super().__getattribute__(name) - - def _proxy_resolve(self): - http_proxy = getenv('HTTP_PROXY') - if http_proxy: - session = super().__getattribute__('__dict__')['session'] - session.proxies = { - 'http': http_proxy, - 'https': http_proxy - } - session.verify = False - def load_tests( self, tests: list[TestItem], From 64eef2e5d90f9606bc028149c6c3428d33cfcef2 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 09:29:18 +0200 Subject: [PATCH 38/72] =?UTF-8?q?bump:=20version=202.8.2.dev17=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 38eb978..5c7139a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev17" +version = "2.8.2.dev18" dependencies = [ "requests>=2.29.0", From f8ef08ef1032f1dc499a178e4c33179737d4ee6b Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 09:37:45 +0200 Subject: [PATCH 39/72] fix: remove proxy for now as I can't resolve it reliably --- pytestomatio/connect/connector.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index b01e0b7..7556110 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -16,20 +16,6 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.session.verify = True self.jwt: str = '' self.api_key = api_key - self._proxy_resolve() - - def _proxy_resolve(self): - http_proxy = getenv("HTTP_PROXY") - if http_proxy: - self.session.proxies = {"http": http_proxy, "https": http_proxy} - self.session.verify = False - else: - self.session.verify = True - - def __getattribute__(self, name: str): - if name == "session": - self._proxy_resolve() - return super().__getattribute__(name) def load_tests( self, From 4027c8d18eea7c9d0531163a2270e75e8d236ad6 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 09:37:49 +0200 Subject: [PATCH 40/72] =?UTF-8?q?bump:=20version=202.8.2.dev18=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev19?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5c7139a..efa5cc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev18" +version = "2.8.2.dev19" dependencies = [ "requests>=2.29.0", From d8c8d01274c8aeac46a55e50558d812dd497c71b Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:02:45 +0200 Subject: [PATCH 41/72] feat: proxy aware session --- pytestomatio/connect/connector.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 7556110..d0a46e2 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -16,6 +16,23 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.session.verify = True self.jwt: str = '' self.api_key = api_key + self.proxies = {} + + @property + def session(self): + """Resolve and apply proxy settings each time session is accessed.""" + if self.session is None: + self.session = requests.Session() + + http_proxy = getenv("HTTP_PROXY") + if http_proxy: + self.session.proxies = {"http": http_proxy, "https": http_proxy} + self.session.verify = False + else: + self.session.proxies.clear() + self.session.verify = True + + return self.session def load_tests( self, From d956dc0d9f3b182c4e8a2ac8344952db34265edb Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:02:50 +0200 Subject: [PATCH 42/72] =?UTF-8?q?bump:=20version=202.8.2.dev19=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index efa5cc0..c304f9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev19" +version = "2.8.2.dev20" dependencies = [ "requests>=2.29.0", From 6dabafb5d8a7b2d0106df0c267fb517ffa597302 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:11:01 +0200 Subject: [PATCH 43/72] fix: fix getter --- pytestomatio/connect/connector.py | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index d0a46e2..557a3cb 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -12,27 +12,25 @@ class Connector: def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = None): self.base_url = base_url - self.session = requests.Session() - self.session.verify = True + self._session = requests.Session() self.jwt: str = '' self.api_key = api_key - self.proxies = {} @property - def session(self): + def _session(self): """Resolve and apply proxy settings each time session is accessed.""" - if self.session is None: - self.session = requests.Session() + if self._session is None: + self._session = requests.Session() http_proxy = getenv("HTTP_PROXY") if http_proxy: - self.session.proxies = {"http": http_proxy, "https": http_proxy} - self.session.verify = False + self._session.proxies = {"http": http_proxy, "https": http_proxy} + self._session.verify = False else: - self.session.proxies.clear() - self.session.verify = True + self._session.proxies.clear() + self._session.verify = True - return self.session + return self._session def load_tests( self, @@ -66,7 +64,7 @@ def load_tests( }) try: - response = self.session.post(f'{self.base_url}/api/load?api_key={self.api_key}', json=request) + response = self._session.post(f'{self.base_url}/api/load?api_key={self.api_key}', json=request) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') return @@ -84,7 +82,7 @@ def load_tests( def get_tests(self, test_metadata: list[TestItem]) -> dict: # with safe_request('Failed to get test ids from testomat.io'): - response = self.session.get(f'{self.base_url}/api/test_data?api_key={self.api_key}') + 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: @@ -100,7 +98,7 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ } filtered_request = {k: v for k, v in request.items() if v is not None} try: - response = self.session.post(f'{self.base_url}/api/reporter', 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 @@ -130,7 +128,7 @@ def update_test_run(self, id: str, title: str, group_title, 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}', json=filtered_request) + response = self._session.put(f'{self.base_url}/api/reporter/{id}', json=filtered_request) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') return @@ -175,7 +173,7 @@ def update_test_status(self, run_id: str, } filtered_request = {k: v for k, v in request.items() if v is not None} try: - response = self.session.post(f'{self.base_url}/api/reporter/{run_id}/testrun?api_key={self.api_key}', + response = self._session.post(f'{self.base_url}/api/reporter/{run_id}/testrun?api_key={self.api_key}', json=filtered_request) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') @@ -193,7 +191,7 @@ def update_test_status(self, run_id: str, def finish_test_run(self, run_id: str, is_final=False) -> None: status_event = 'finish_parallel' if is_final else 'finish' try: - self.session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', + self._session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', json={"status_event": status_event}) except ConnectionError: log.error(f'Failed to connect to {self.base_url}') @@ -206,4 +204,4 @@ def finish_test_run(self, run_id: str, is_final=False) -> None: return def disconnect(self): - self.session.close() + self._session.close() From fea5fc2487599a68543c9461df107b04e0d7a3da Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:11:05 +0200 Subject: [PATCH 44/72] =?UTF-8?q?bump:=20version=202.8.2.dev20=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c304f9f..9df5555 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev20" +version = "2.8.2.dev21" dependencies = [ "requests>=2.29.0", From b14c44a78fcb444801de69c00b14956bd53b605e Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:25:03 +0200 Subject: [PATCH 45/72] fix: fix setter --- pytestomatio/connect/connector.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 557a3cb..721f33a 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -17,21 +17,29 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non self.api_key = api_key @property - def _session(self): - """Resolve and apply proxy settings each time session is accessed.""" + def session(self): + """Get the session, creating it and applying proxy settings if necessary.""" if self._session is None: self._session = requests.Session() + self._apply_proxy_settings() + return self._session + + @session.setter + def session(self, value): + """Allow setting a custom session, while still applying proxy settings.""" + self._session = value + self._apply_proxy_settings() + def _apply_proxy_settings(self): + """Apply proxy settings based on environment variables.""" http_proxy = getenv("HTTP_PROXY") if http_proxy: self._session.proxies = {"http": http_proxy, "https": http_proxy} self._session.verify = False else: - self._session.proxies.clear() + self._session.proxies.clear() # Clear proxies if HTTP_PROXY is not set self._session.verify = True - return self._session - def load_tests( self, tests: list[TestItem], From d5900be72b1fdb4738dc5349bc07756bb69ee7bf Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 14:25:07 +0200 Subject: [PATCH 46/72] =?UTF-8?q?bump:=20version=202.8.2.dev21=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9df5555..95102eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev21" +version = "2.8.2.dev22" dependencies = [ "requests>=2.29.0", From 9b383aa995f75083b6a3c331929142d2a4ebd9b2 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 23:11:15 +0200 Subject: [PATCH 47/72] refactor: debug connectivity error --- pytestomatio/connect/connector.py | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 721f33a..4acac09 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -73,14 +73,14 @@ def load_tests( try: response = self._session.post(f'{self.base_url}/api/load?api_key={self.api_key}', json=request) - except ConnectionError: - log.error(f'Failed to connect to {self.base_url}') + except ConnectionError as ce: + log.error(f'Failed to connect to {self.base_url}: {ce}') return - except HTTPError: - log.error(f'Failed to connect to {self.base_url}') + except HTTPError as he: + log.error(f'HTTP error occurred while connecting to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue. {e}') + log.error(f'An unexpected exception occurred. Please report an issue: {e}') return if response.status_code < 400: @@ -107,14 +107,14 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ filtered_request = {k: v for k, v in request.items() if v is not None} try: 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}') + except ConnectionError as ce: + log.error(f'Failed to connect to {self.base_url}: {ce}') return - except HTTPError: - log.error(f'Failed to connect to {self.base_url}') + except HTTPError as he: + log.error(f'HTTP error occurred while connecting to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue. {e}') + log.error(f'An unexpected exception occurred. Please report an issue: {e}') return if response.status_code == 200: @@ -141,10 +141,10 @@ def update_test_run(self, id: str, title: str, group_title, log.error(f'Failed to connect to {self.base_url}: {ce}') return except HTTPError as he: - log.error(f'Failed to connect to {self.base_url}: {he}') + log.error(f'HTTP error occurred while connecting to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue: {e}') + log.error(f'An unexpected exception occurred. Please report an issue: {e}') return if response.status_code == 200: @@ -183,14 +183,14 @@ def update_test_status(self, run_id: str, try: response = self._session.post(f'{self.base_url}/api/reporter/{run_id}/testrun?api_key={self.api_key}', json=filtered_request) - except ConnectionError: - log.error(f'Failed to connect to {self.base_url}') + except ConnectionError as ce: + log.error(f'Failed to connect to {self.base_url}: {ce}') return - except HTTPError: - log.error(f'Failed to connect to {self.base_url}') + except HTTPError as he: + log.error(f'HTTP error occurred while connecting to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue. {e}') + log.error(f'An unexpected exception occurred. Please report an issue: {e}') return if response.status_code == 200: log.info('Test status updated') @@ -201,14 +201,14 @@ def finish_test_run(self, run_id: str, is_final=False) -> None: try: self._session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', json={"status_event": status_event}) - except ConnectionError: - log.error(f'Failed to connect to {self.base_url}') + except ConnectionError as ce: + log.error(f'Failed to connect to {self.base_url}: {ce}') return - except HTTPError: - log.error(f'Failed to connect to {self.base_url}') + except HTTPError as he: + log.error(f'HTTP error occurred while connecting to {self.base_url}: {he}') return except Exception as e: - log.error(f'Generic exception happened. Please report an issue. {e}') + log.error(f'An unexpected exception occurred. Please report an issue: {e}') return def disconnect(self): From 90be71432c3c722b41929c9bfe1e37d48d22c2a4 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 23:11:21 +0200 Subject: [PATCH 48/72] =?UTF-8?q?bump:=20version=202.8.2.dev22=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 95102eb..82d554b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev22" +version = "2.8.2.dev23" dependencies = [ "requests>=2.29.0", From 91a2d678b73b08bd1d7db36c1514c73746facf2d Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 23:14:40 +0200 Subject: [PATCH 49/72] fix: alway check proxy settings --- pytestomatio/connect/connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 4acac09..9a9d27a 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -21,7 +21,7 @@ def session(self): """Get the session, creating it and applying proxy settings if necessary.""" if self._session is None: self._session = requests.Session() - self._apply_proxy_settings() + self._apply_proxy_settings() return self._session @session.setter From 433643109f636c37133acd8ef85c72577565de38 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 2 Sep 2024 23:14:48 +0200 Subject: [PATCH 50/72] =?UTF-8?q?bump:=20version=202.8.2.dev23=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 82d554b..7c79be2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev23" +version = "2.8.2.dev24" dependencies = [ "requests>=2.29.0", From 3ee85f964ca7589c25b0dd9a2ac102a99eef3736 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 00:46:55 +0200 Subject: [PATCH 51/72] fix: connection fallback when proxy is unavilable --- pytestomatio/connect/connector.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 9a9d27a..b7574d9 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -31,15 +31,29 @@ def session(self, value): self._apply_proxy_settings() def _apply_proxy_settings(self): - """Apply proxy settings based on environment variables.""" + """Apply proxy settings based on environment variables, fallback to no proxy if unavailable.""" http_proxy = getenv("HTTP_PROXY") if http_proxy: self._session.proxies = {"http": http_proxy, "https": http_proxy} self._session.verify = False + + if not self._test_proxy_connection(): + print("Proxy is unavailable. Falling back to a direct connection.") + self._session.proxies.clear() + self._session.verify = True else: - self._session.proxies.clear() # Clear proxies if HTTP_PROXY is not set + self._session.proxies.clear() self._session.verify = True + def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json"): + """Test if the proxy connection is available.""" + try: + response = self._session.get(test_url, timeout=5) + response.raise_for_status() + return True + except requests.exceptions.RequestException: + return False + def load_tests( self, tests: list[TestItem], From e89a62c1a1597bc1e6627621b85c771f118a04c1 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 00:47:07 +0200 Subject: [PATCH 52/72] =?UTF-8?q?bump:=20version=202.8.2.dev24=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev25?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7c79be2..3e40c2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev24" +version = "2.8.2.dev25" dependencies = [ "requests>=2.29.0", From 5c82e24be505c2eb1a6ef2b1fc05441c94b00804 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 09:34:49 +0200 Subject: [PATCH 53/72] fix: debug --- pytestomatio/connect/connector.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index b7574d9..d2d7307 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -33,15 +33,18 @@ def session(self, value): def _apply_proxy_settings(self): """Apply proxy settings based on environment variables, fallback to no proxy if unavailable.""" http_proxy = getenv("HTTP_PROXY") + log.debug(f"HTTP_PROXY: {http_proxy}") if http_proxy: self._session.proxies = {"http": http_proxy, "https": http_proxy} self._session.verify = False + log.debug(f"Proxy settings applied: {self._session.proxies}") if not self._test_proxy_connection(): - print("Proxy is unavailable. Falling back to a direct connection.") + log.info("Proxy is unavailable. Falling back to a direct connection.") self._session.proxies.clear() self._session.verify = True else: + log.debug("No proxy settings found. Using a direct connection.") self._session.proxies.clear() self._session.verify = True From 367d80bf81ffc649f7a803adadc51081c321aaa1 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 09:34:55 +0200 Subject: [PATCH 54/72] =?UTF-8?q?bump:=20version=202.8.2.dev25=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3e40c2a..91d2bb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev25" +version = "2.8.2.dev26" dependencies = [ "requests>=2.29.0", From bceb1c2dd3214a3fb8542d9ade7e5b08ed412cbe Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 11:27:41 +0200 Subject: [PATCH 55/72] fix: Fix session usage --- pytestomatio/connect/connector.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index d2d7307..2554931 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -19,8 +19,6 @@ def __init__(self, base_url: str = 'https://app.testomat.io', api_key: str = Non @property def session(self): """Get the session, creating it and applying proxy settings if necessary.""" - if self._session is None: - self._session = requests.Session() self._apply_proxy_settings() return self._session @@ -37,14 +35,14 @@ def _apply_proxy_settings(self): if http_proxy: self._session.proxies = {"http": http_proxy, "https": http_proxy} self._session.verify = False - log.debug(f"Proxy settings applied: {self._session.proxies}") + log.info(f"Proxy settings applied: {self._session.proxies}") if not self._test_proxy_connection(): log.info("Proxy is unavailable. Falling back to a direct connection.") self._session.proxies.clear() self._session.verify = True else: - log.debug("No proxy settings found. Using a direct connection.") + log.info("No proxy settings found. Using a direct connection.") self._session.proxies.clear() self._session.verify = True @@ -89,7 +87,7 @@ def load_tests( }) try: - response = self._session.post(f'{self.base_url}/api/load?api_key={self.api_key}', json=request) + response = self.session.post(f'{self.base_url}/api/load?api_key={self.api_key}', json=request) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') return @@ -107,7 +105,7 @@ def load_tests( def get_tests(self, test_metadata: list[TestItem]) -> dict: # with safe_request('Failed to get test ids from testomat.io'): - response = self._session.get(f'{self.base_url}/api/test_data?api_key={self.api_key}') + 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: @@ -123,7 +121,7 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_ } filtered_request = {k: v for k, v in request.items() if v is not None} try: - response = self._session.post(f'{self.base_url}/api/reporter', json=filtered_request) + response = self.session.post(f'{self.base_url}/api/reporter', json=filtered_request) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') return @@ -153,7 +151,7 @@ def update_test_run(self, id: str, title: str, group_title, 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}', json=filtered_request) + response = self.session.put(f'{self.base_url}/api/reporter/{id}', json=filtered_request) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') return @@ -198,7 +196,7 @@ def update_test_status(self, run_id: str, } filtered_request = {k: v for k, v in request.items() if v is not None} try: - response = self._session.post(f'{self.base_url}/api/reporter/{run_id}/testrun?api_key={self.api_key}', + response = self.session.post(f'{self.base_url}/api/reporter/{run_id}/testrun?api_key={self.api_key}', json=filtered_request) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') @@ -216,7 +214,7 @@ def update_test_status(self, run_id: str, def finish_test_run(self, run_id: str, is_final=False) -> None: status_event = 'finish_parallel' if is_final else 'finish' try: - self._session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', + self.session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}', json={"status_event": status_event}) except ConnectionError as ce: log.error(f'Failed to connect to {self.base_url}: {ce}') @@ -229,4 +227,4 @@ def finish_test_run(self, run_id: str, is_final=False) -> None: return def disconnect(self): - self._session.close() + self.session.close() From 9b19b456ec5c1aaebd3d5826f957d3d8507f788e Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 11:27:54 +0200 Subject: [PATCH 56/72] =?UTF-8?q?bump:=20version=202.8.2.dev26=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 91d2bb7..112ddfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev26" +version = "2.8.2.dev27" dependencies = [ "requests>=2.29.0", From 6b8cc68462c31311a754119106299aa7ce010de7 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 11:51:42 +0200 Subject: [PATCH 57/72] fix: debug further --- pytestomatio/connect/connector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 2554931..a41a929 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -45,14 +45,17 @@ def _apply_proxy_settings(self): log.info("No proxy settings found. Using a direct connection.") self._session.proxies.clear() self._session.verify = True + self._test_proxy_connection() def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json"): """Test if the proxy connection is available.""" try: response = self._session.get(test_url, timeout=5) response.raise_for_status() + log.info("Internet connection is available.") return True except requests.exceptions.RequestException: + log.error("Internet connection is unavailable.") return False def load_tests( From 3de6f66b967df80157b1c3b2b55ebc3750ad19fc Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 11:51:48 +0200 Subject: [PATCH 58/72] =?UTF-8?q?bump:=20version=202.8.2.dev27=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 112ddfe..40a1c0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev27" +version = "2.8.2.dev28" dependencies = [ "requests>=2.29.0", From c02128045ae3649909f68315a724cac0269ccdd9 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 12:35:17 +0200 Subject: [PATCH 59/72] fix: more debug logs --- pytestomatio/connect/connector.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index a41a929..ede4a84 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -49,6 +49,8 @@ def _apply_proxy_settings(self): def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json"): """Test if the proxy connection is available.""" + log.debug("Current session: %s", self._session.proxies) + log.debug("Current verify: %s", self._session.verify) try: response = self._session.get(test_url, timeout=5) response.raise_for_status() From d65fbd1552199095b50dd006fd084a447f90296a Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 12:35:22 +0200 Subject: [PATCH 60/72] =?UTF-8?q?bump:=20version=202.8.2.dev28=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 40a1c0a..c35f719 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev28" +version = "2.8.2.dev29" dependencies = [ "requests>=2.29.0", From b46e7ba6e932c371f072c339c9a7a35063da4aa3 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 13:19:46 +0200 Subject: [PATCH 61/72] fix: retry connection for a while --- pytestomatio/connect/connector.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index ede4a84..4639b7d 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -5,6 +5,7 @@ from os import getenv from pytestomatio.utils.helper import safe_string_list from pytestomatio.testing.testItem import TestItem +import time log = logging.getLogger('pytestomatio') @@ -37,7 +38,7 @@ def _apply_proxy_settings(self): self._session.verify = False log.info(f"Proxy settings applied: {self._session.proxies}") - if not self._test_proxy_connection(): + if not self._test_proxy_connection(timeout=1): log.info("Proxy is unavailable. Falling back to a direct connection.") self._session.proxies.clear() self._session.verify = True @@ -47,18 +48,23 @@ def _apply_proxy_settings(self): self._session.verify = True self._test_proxy_connection() - def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json"): - """Test if the proxy connection is available.""" + def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json", timeout=30, retry_interval=1): log.debug("Current session: %s", self._session.proxies) log.debug("Current verify: %s", self._session.verify) - try: - response = self._session.get(test_url, timeout=5) - response.raise_for_status() - log.info("Internet connection is available.") - return True - except requests.exceptions.RequestException: - log.error("Internet connection is unavailable.") - return False + + start_time = time.time() + while time.time() - start_time < timeout: + try: + response = self._session.get(test_url, timeout=5) + response.raise_for_status() + log.info("Internet connection is available.") + return True + except requests.exceptions.RequestException as e: + log.error("Internet connection is unavailable. Error: %s", e) + time.sleep(retry_interval) + + log.error("Internet connection check timed out after %d seconds.", timeout) + return False def load_tests( self, From 7b6aeeb7ec52a17df69fe342520382b4bb645a93 Mon Sep 17 00:00:00 2001 From: Tiko Date: Tue, 3 Sep 2024 13:19:52 +0200 Subject: [PATCH 62/72] =?UTF-8?q?bump:=20version=202.8.2.dev29=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c35f719..d904a35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev29" +version = "2.8.2.dev30" dependencies = [ "requests>=2.29.0", From f675cce7e9dcb165bfd15cf982443ee1bc9c7e1c Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 4 Sep 2024 22:22:00 +0200 Subject: [PATCH 63/72] fix: upload files in bulk --- pytestomatio/connect/connector.py | 8 ++++---- pytestomatio/connect/s3_connector.py | 9 +++++++++ pytestomatio/testomatio/testomatio.py | 21 ++++++++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/pytestomatio/connect/connector.py b/pytestomatio/connect/connector.py index 4639b7d..33db927 100644 --- a/pytestomatio/connect/connector.py +++ b/pytestomatio/connect/connector.py @@ -36,14 +36,14 @@ def _apply_proxy_settings(self): if http_proxy: self._session.proxies = {"http": http_proxy, "https": http_proxy} self._session.verify = False - log.info(f"Proxy settings applied: {self._session.proxies}") + log.debug(f"Proxy settings applied: {self._session.proxies}") if not self._test_proxy_connection(timeout=1): - log.info("Proxy is unavailable. Falling back to a direct connection.") + log.debug("Proxy is unavailable. Falling back to a direct connection.") self._session.proxies.clear() self._session.verify = True else: - log.info("No proxy settings found. Using a direct connection.") + log.debug("No proxy settings found. Using a direct connection.") self._session.proxies.clear() self._session.verify = True self._test_proxy_connection() @@ -57,7 +57,7 @@ def _test_proxy_connection(self, test_url="https://api.ipify.org?format=json", t try: response = self._session.get(test_url, timeout=5) response.raise_for_status() - log.info("Internet connection is available.") + log.debug("Internet connection is available.") return True except requests.exceptions.RequestException as e: log.error("Internet connection is unavailable. Error: %s", e) diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index 31b824f..d9b4625 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -49,6 +49,15 @@ def login(self): self._is_logged_in = True log.info('s3 session created') + # TODO: upload files async + def upload_files(self, file_list, bucket_name: str = None): + links = [] + for file_path, key in file_list: + link = self.upload_file(file_path=file_path, key=key, bucket_name=bucket_name) + links.extend(link) + return [link for link in links if link is not None] + + def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) -> Optional[str]: if not self._is_logged_in: log.warning('s3 session is not created, creating new one') diff --git a/pytestomatio/testomatio/testomatio.py b/pytestomatio/testomatio/testomatio.py index 68552dd..19e9896 100644 --- a/pytestomatio/testomatio/testomatio.py +++ b/pytestomatio/testomatio/testomatio.py @@ -2,6 +2,9 @@ from .testRunConfig import TestRunConfig from pytestomatio.connect.s3_connector import S3Connector from pytestomatio.connect.connector import Connector +import logging + +log = logging.getLogger(__name__) class Testomatio: @@ -23,7 +26,19 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non return "" return self.s3_connector.upload_file_object(file_bytes, key, bucket_name) - def add_artifacts(self, node: Function, urls: list[str]) -> None: - artifact_urls = node.stash.get("artifact_urls", []) + def add_artifacts(self, *args) -> None: + urls = None + for arg in args: + if isinstance(arg, list): + urls = arg + if not urls: + log.warn("Failed to add artifacts. No valid list of url has been provided") + return + + if not hasattr(self, "request"): + log.warn("Couldn't attach link to the test. Make sure pytestomatio is configured correctly.") + return + + artifact_urls = self.request.node.stash.get("artifact_urls", []) artifact_urls.extend(urls) - node.stash["artifact_urls"] = [ url for url in artifact_urls if url is not None] + self.request.node.stash["artifact_urls"] = [ url for url in artifact_urls if url is not None] From f0a5f3162d986aad2811c1f51c136869a0feac38 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 4 Sep 2024 22:22:22 +0200 Subject: [PATCH 64/72] =?UTF-8?q?bump:=20version=202.8.2.dev30=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d904a35..86a0fe2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev30" +version = "2.8.2.dev31" dependencies = [ "requests>=2.29.0", From 2e7f071a198604436f562e73bb4507c40539ef57 Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 4 Sep 2024 23:45:30 +0200 Subject: [PATCH 65/72] fix: fix resolving urls --- pytestomatio/connect/s3_connector.py | 2 +- pytestomatio/testomatio/testomatio.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index d9b4625..5f3c3c4 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -54,7 +54,7 @@ def upload_files(self, file_list, bucket_name: str = None): links = [] for file_path, key in file_list: link = self.upload_file(file_path=file_path, key=key, bucket_name=bucket_name) - links.extend(link) + links.append(link) return [link for link in links if link is not None] diff --git a/pytestomatio/testomatio/testomatio.py b/pytestomatio/testomatio/testomatio.py index 19e9896..f5d3166 100644 --- a/pytestomatio/testomatio/testomatio.py +++ b/pytestomatio/testomatio/testomatio.py @@ -14,15 +14,21 @@ def __init__(self, test_run_config: TestRunConfig = None, self.test_run_config: TestRunConfig or None = test_run_config self.connector: Connector or None = None + def upload_files(self, files_list, bucket_name: str = None) -> str: + if self.test_run_config.test_run_id is None: + log.debug("Skipping file upload when testomatio test run is not created") + return "" + return self.s3_connector.upload_files(files_list, bucket_name) + def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) -> str: if self.test_run_config.test_run_id is None: - print("Skipping file upload when testomatio test run is not created") + log.debug("Skipping file upload when testomatio test run is not created") return "" return self.s3_connector.upload_file(file_path, key, bucket_name) def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = None) -> str: if self.test_run_config.test_run_id is None: - print("Skipping file upload when testomatio test run is not created") + log.debug("Skipping file upload when testomatio test run is not created") return "" return self.s3_connector.upload_file_object(file_bytes, key, bucket_name) From 7121ffe7dbd67c6861cb5dd0cdcfb6a6f5014dde Mon Sep 17 00:00:00 2001 From: Tiko Date: Wed, 4 Sep 2024 23:45:34 +0200 Subject: [PATCH 66/72] =?UTF-8?q?bump:=20version=202.8.2.dev31=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 86a0fe2..62ccb3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev31" +version = "2.8.2.dev32" dependencies = [ "requests>=2.29.0", From 2cb4db65813af38e5cd55e3052cf6a34f2060dcc Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 09:50:20 +0200 Subject: [PATCH 67/72] fix: add_artifacts depends on the pytest node --- pytestomatio/testomatio/testomatio.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pytestomatio/testomatio/testomatio.py b/pytestomatio/testomatio/testomatio.py index f5d3166..c8ea723 100644 --- a/pytestomatio/testomatio/testomatio.py +++ b/pytestomatio/testomatio/testomatio.py @@ -32,19 +32,8 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non return "" return self.s3_connector.upload_file_object(file_bytes, key, bucket_name) - def add_artifacts(self, *args) -> None: - urls = None - for arg in args: - if isinstance(arg, list): - urls = arg - if not urls: - log.warn("Failed to add artifacts. No valid list of url has been provided") - return + def add_artifacts(self, node: Function, url_list) -> None: + artifact_urls = node.stash.get("artifact_urls", []) + artifact_urls.extend(url_list) + node.stash["artifact_urls"] = [ url for url in artifact_urls if url is not None] - if not hasattr(self, "request"): - log.warn("Couldn't attach link to the test. Make sure pytestomatio is configured correctly.") - return - - artifact_urls = self.request.node.stash.get("artifact_urls", []) - artifact_urls.extend(urls) - self.request.node.stash["artifact_urls"] = [ url for url in artifact_urls if url is not None] From 365d957f32e8752fa05af0f250375d7d0f44682f Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 09:50:24 +0200 Subject: [PATCH 68/72] =?UTF-8?q?bump:=20version=202.8.2.dev32=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- pytestomatio/connect/s3_connector.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 62ccb3b..61d4f31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev32" +version = "2.8.2.dev33" dependencies = [ "requests>=2.29.0", diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index 5f3c3c4..2c79617 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -15,6 +15,7 @@ def parse_endpoint(endpoint: str = None) -> Optional[str]: return endpoint[7:] return endpoint +# TODO: review error handling. It should be save, and only create log entries without effecting test execution. class S3Connector: def __init__(self, aws_region_name: Optional[str], From a2ac056559f0d7bdc7921e7e45ed088219b7a096 Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 11:09:46 +0200 Subject: [PATCH 69/72] fix: handle not created test run --- pytestomatio/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 2a4ee83..4539920 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -51,8 +51,12 @@ def pytest_configure(config: Config): run_id = pytest.testomatio.test_run_config.test_run_id if not run_id: run_details = pytest.testomatio.connector.create_test_run(**run.to_dict()) - run_id = run_details.get('uid') - run.save_run_id(run_id) + if run_details: + run_id = run_details.get('uid') + run.save_run_id(run_id) + else: + log.error("Failed to create testrun on Testomat.io") + From 399bd4bb953683a37a1b8ea2425c03ebfc8a44c2 Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 11:09:52 +0200 Subject: [PATCH 70/72] =?UTF-8?q?bump:=20version=202.8.2.dev33=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev34?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 61d4f31..f17ea51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev33" +version = "2.8.2.dev34" dependencies = [ "requests>=2.29.0", From 42d155f8d84ca043acb935021270980bc0908828 Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 14:13:19 +0200 Subject: [PATCH 71/72] fix: enforce artifacts to be returning inline when requested --- pytestomatio/connect/s3_connector.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pytestomatio/connect/s3_connector.py b/pytestomatio/connect/s3_connector.py index 2c79617..17fbd0f 100644 --- a/pytestomatio/connect/s3_connector.py +++ b/pytestomatio/connect/s3_connector.py @@ -75,7 +75,16 @@ def upload_file(self, file_path: str, key: str = None, bucket_name: str = None) try: log.info(f'uploading artifact {file_path} to s3://{bucket_name}/{key}') - self.client.upload_file(file_path, bucket_name, key, ExtraArgs={'ACL': self.acl, 'ContentType': content_type}) + self.client.upload_file( + file_path, + bucket_name, + key, + ExtraArgs={ + 'ACL': self.acl, + 'ContentType': content_type, + 'ContentDisposition': 'inline' + } + ) log.info(f'artifact {file_path} uploaded to s3://{bucket_name}/{key}') return f'https://{bucket_name}.{self.endpoint}/{key}' except Exception as e: @@ -96,7 +105,16 @@ def upload_file_object(self, file_bytes: bytes, key: str, bucket_name: str = Non try: log.info(f'uploading artifact {key} to s3://{bucket_name}/{key}') - self.client.upload_fileobj(file, bucket_name, key, ExtraArgs={'ACL': self.acl, 'ContentType': content_type}) + self.client.upload_fileobj( + file, + bucket_name, + key, + ExtraArgs={ + 'ACL': self.acl, + 'ContentType': content_type, + 'ContentDisposition': 'inline' + } + ) log.info(f'artifact {key} uploaded to s3://{bucket_name}/{key}') return f'https://{bucket_name}.{self.endpoint}/{key}' except Exception as e: From 38f9ad9a143683e89660da1db37f207361590d13 Mon Sep 17 00:00:00 2001 From: Tiko Date: Thu, 5 Sep 2024 14:13:26 +0200 Subject: [PATCH 72/72] =?UTF-8?q?bump:=20version=202.8.2.dev34=20=E2=86=92?= =?UTF-8?q?=202.8.2.dev35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f17ea51..bad63fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.8.2.dev34" +version = "2.8.2.dev35" dependencies = [ "requests>=2.29.0",