Skip to content

Commit

Permalink
Merge pull request #183 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth committed Apr 28, 2022
2 parents 6fc043d + 91d115d commit 1593bc1
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 27 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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: |
Expand All @@ -111,11 +110,11 @@ 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 }}
git add ${{ env.VERSION_FILE }}
git commit -m "Version update"
git push origin develop
git push
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## [Unreleased]
### Fixed
- Issue [#180](https://github.com/reportportal/client-Python/issues/180):
logger crash on attachments, by @HardNorth
- 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
### 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
Expand Down
1 change: 0 additions & 1 deletion reportportal_client/_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""Report Portal client context storing and retrieving module."""
from threading import local


__INSTANCES = local()


Expand Down
22 changes: 22 additions & 0 deletions reportportal_client/_local/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
17 changes: 9 additions & 8 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def emit(self, record):
Emit function.
:param record: a log Record of requests
:return: log ID
"""
msg = ''

Expand All @@ -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
3 changes: 1 addition & 2 deletions reportportal_client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions reportportal_client/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions tests/logs/test_rp_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 9 additions & 0 deletions tests/steps/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1593bc1

Please sign in to comment.