From 051ccec8e7d78775c7ccc3a6f094bec8b21b5534 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Apr 2022 12:15:26 +0300 Subject: [PATCH 1/5] Release updates --- .github/workflows/release.yml | 15 +++++++-------- CHANGELOG.md | 4 +++- setup.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5402510..a4a869cf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,6 +62,12 @@ jobs: python setup.py sdist bdist_wheel twine upload dist/* + - name: Checkout develop branch + uses: actions/checkout@v2 + with: + ref: 'develop' + fetch-depth: 0 + - name: Update CHANGELOG.md id: changelogUpdate run: | @@ -74,7 +80,6 @@ jobs: mv ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} ${{ env.CHANGE_LOG_FILE }} git add ${{ env.CHANGE_LOG_FILE }} git commit -m "Changelog update" - git push - name: Read changelog Entry id: readChangelogEntry @@ -95,12 +100,6 @@ jobs: draft: false prerelease: false - - name: Checkout develop branch - uses: actions/checkout@v2 - with: - ref: 'develop' - fetch-depth: 0 - - name: Merge release branch into develop id: mergeIntoDevelop run: | @@ -118,4 +117,4 @@ jobs: mv ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.VERSION_FILE }} git add ${{ env.VERSION_FILE }} git commit -m "Version update" - git push origin develop + git push diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e755dae..b5f501b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog ## [Unreleased] + +## [5.2.1] ### Fixed - Issue [#180](https://github.com/reportportal/client-Python/issues/180): logger crash on attachments, by @HardNorth ### Changed -- Log processing does not stop on the first error now. +- Log processing does not stop on the first error now, by @HardNorth ## [5.2.0] ### Changed diff --git a/setup.py b/setup.py index aafa0e14..4e5d6e53 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -__version__ = '5.2.1' +__version__ = '5.2.2' with open('requirements.txt') as f: requirements = f.read().splitlines() From 33261cd80af15cb80ee26a073c52321c1dc61011 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Apr 2022 12:55:41 +0300 Subject: [PATCH 2/5] Release pipeline updates --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4a869cf..650dca55 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -110,8 +110,8 @@ jobs: - name: Update version file id: versionFileUpdate run: | - export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'` - export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'` + export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E "s/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/"` + export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E "s/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/"` sed "s/${CURRENT_VERSION_VALUE}/${NEXT_VERSION_VALUE}/g" ${{ env.VERSION_FILE }} > ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} rm ${{ env.VERSION_FILE }} mv ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.VERSION_FILE }} From 62952804d3a47e6ec140693ff1deae140f936279 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 28 Apr 2022 12:39:11 +0300 Subject: [PATCH 3/5] Fixes #182 --- CHANGELOG.md | 5 +++-- reportportal_client/logs/__init__.py | 17 +++++++++-------- reportportal_client/service.py | 3 +-- tests/logs/test_rp_log_handler.py | 12 ++++++++++++ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f501b9..bf4fdc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Changelog ## [Unreleased] +### Fixed +- Issue [#182](https://github.com/reportportal/client-Python/issues/182): logger crash on attachments, by @HardNorth ## [5.2.1] ### Fixed -- Issue [#180](https://github.com/reportportal/client-Python/issues/180): -logger crash on attachments, by @HardNorth +- Issue [#180](https://github.com/reportportal/client-Python/issues/180): logger crash on attachments, by @HardNorth ### Changed - Log processing does not stop on the first error now, by @HardNorth diff --git a/reportportal_client/logs/__init__.py b/reportportal_client/logs/__init__.py index 8be41d63..0ec11232 100644 --- a/reportportal_client/logs/__init__.py +++ b/reportportal_client/logs/__init__.py @@ -138,7 +138,6 @@ def emit(self, record): Emit function. :param record: a log Record of requests - :return: log ID """ msg = '' @@ -152,10 +151,12 @@ def emit(self, record): for level in self._sorted_levelnos: if level <= record.levelno: rp_client = current() - return rp_client.log( - timestamp(), - msg, - level=self._loglevel_map[level], - attachment=getattr(record, 'attachment'), - item_id=rp_client.current_item() - ) + if rp_client: + rp_client.log( + timestamp(), + msg, + level=self._loglevel_map[level], + attachment=getattr(record, 'attachment'), + item_id=rp_client.current_item() + ) + return diff --git a/reportportal_client/service.py b/reportportal_client/service.py index 7a35a93f..9f374e07 100644 --- a/reportportal_client/service.py +++ b/reportportal_client/service.py @@ -497,7 +497,6 @@ def log(self, time, message, level=None, attachment=None, item_id=None): :param level: :param attachment: files :param item_id: id of item - :return: id of item from response """ data = { "launchUuid": self.launch_id, @@ -509,7 +508,7 @@ def log(self, time, message, level=None, attachment=None, item_id=None): data["itemUuid"] = item_id if attachment: data["attachment"] = attachment - return self._log_batch(data) + self._log_batch(data) def _log_batch(self, log_data, force=False): """ diff --git a/tests/logs/test_rp_log_handler.py b/tests/logs/test_rp_log_handler.py index f6424aee..e981417d 100644 --- a/tests/logs/test_rp_log_handler.py +++ b/tests/logs/test_rp_log_handler.py @@ -95,3 +95,15 @@ def test_emit_custom_level(mocked_handle): assert mock_client.log.call_count == 1 call_kwargs = mock_client.log.call_args[1] assert call_kwargs['level'] == 'WARN' + + +@mock.patch('reportportal_client.logs.logging.Logger.handle') +def test_emit_null_client_no_error(mocked_handle): + test_message = 'test message' + RPLogger('test_logger').log(30, test_message) + record = mocked_handle.call_args[0][0] + + set_current(None) + + log_handler = RPLogHandler() + log_handler.emit(record) From 86163329b443b42fbbf71052be22375bda6c99fb Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 28 Apr 2022 14:01:39 +0300 Subject: [PATCH 4/5] Type annotations --- reportportal_client/_local/__init__.py | 1 - reportportal_client/_local/__init__.pyi | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 reportportal_client/_local/__init__.pyi diff --git a/reportportal_client/_local/__init__.py b/reportportal_client/_local/__init__.py index f9ac00cd..c26d6d6e 100644 --- a/reportportal_client/_local/__init__.py +++ b/reportportal_client/_local/__init__.py @@ -13,7 +13,6 @@ """Report Portal client context storing and retrieving module.""" from threading import local - __INSTANCES = local() diff --git a/reportportal_client/_local/__init__.pyi b/reportportal_client/_local/__init__.pyi new file mode 100644 index 00000000..b7b14cb5 --- /dev/null +++ b/reportportal_client/_local/__init__.pyi @@ -0,0 +1,22 @@ +# Copyright (c) 2022 https://reportportal.io . +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +from typing import Optional + +from reportportal_client.client import RPClient + + +def current() -> Optional[RPClient]: ... + + +def set_current(client: Optional[RPClient]) -> None: ... From de528644a663c50047386d5761ddc322aa43f5d4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 28 Apr 2022 15:06:26 +0300 Subject: [PATCH 5/5] more nested step tests --- reportportal_client/steps/__init__.py | 4 ++-- tests/steps/test_steps.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/reportportal_client/steps/__init__.py b/reportportal_client/steps/__init__.py index 32777af1..23fc9669 100644 --- a/reportportal_client/steps/__init__.py +++ b/reportportal_client/steps/__init__.py @@ -120,7 +120,7 @@ def __enter__(self): """Enter the runtime context related to this object.""" # Cannot call _local.current() early since it will be initialized # before client put something in there - rp_client = self.client if self.client else current() + rp_client = self.client or current() if not rp_client: return self.__item_id = rp_client.step_reporter \ @@ -138,7 +138,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): """Exit the runtime context related to this object.""" # Cannot call _local.current() early since it will be initialized # before client put something in there - rp_client = self.client if self.client else current() + rp_client = self.client or current() if not rp_client: return # Avoid failure in case if 'rp_client' was 'None' on function start diff --git a/tests/steps/test_steps.py b/tests/steps/test_steps.py index 262e3686..98a853a0 100644 --- a/tests/steps/test_steps.py +++ b/tests/steps/test_steps.py @@ -194,3 +194,12 @@ def test_two_level_nested_step_decorator(rp_client): assert first_id.startswith('post-') assert second_id.startswith('post-') assert first_id != second_id + + +def test_verify_manual_client_bypass_step(rp_client): + set_current(None) + rp_client._item_stack.append(PARENT_STEP_ID) + with step(NESTED_STEP_NAME, rp_client=rp_client): + pass + assert rp_client.session.post.call_count == 1 + assert rp_client.session.put.call_count == 1