From 14b31344ab458a4bcca5b35ae69a7ebbd4c4f6ea Mon Sep 17 00:00:00 2001 From: Dmitrii Gridnev Date: Fri, 22 Nov 2024 09:09:08 +0100 Subject: [PATCH] fix : an issue with the `upload_attachment` method ```log attached.extend(self._upload_attachment(project_code, attachment)) TypeError: 'NoneType' object is not iterable ``` --- qase-python-commons/changelog.md | 11 ++++++++++ qase-python-commons/pyproject.toml | 2 +- .../src/qase/commons/client/api_v1_client.py | 2 +- .../src/qase/commons/client/api_v2_client.py | 22 +++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/qase-python-commons/changelog.md b/qase-python-commons/changelog.md index 60fbb4d0..5f454cbb 100644 --- a/qase-python-commons/changelog.md +++ b/qase-python-commons/changelog.md @@ -1,3 +1,14 @@ +# qase-python-commons@3.2.2 + +## What's new + +Fixed an issue with the `upload_attachment` method: + +```log +attached.extend(self._upload_attachment(project_code, attachment)) +TypeError: 'NoneType' object is not iterable +``` + # qase-python-commons@3.2.1 ## What's new diff --git a/qase-python-commons/pyproject.toml b/qase-python-commons/pyproject.toml index 2cf864fe..73750432 100644 --- a/qase-python-commons/pyproject.toml +++ b/qase-python-commons/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "qase-python-commons" -version = "3.2.1" +version = "3.2.2" description = "A library for Qase TestOps and Qase Report" readme = "README.md" authors = [{name = "Qase Team", email = "support@qase.io"}] diff --git a/qase-python-commons/src/qase/commons/client/api_v1_client.py b/qase-python-commons/src/qase/commons/client/api_v1_client.py index 70f5442e..f55239b3 100644 --- a/qase-python-commons/src/qase/commons/client/api_v1_client.py +++ b/qase-python-commons/src/qase/commons/client/api_v1_client.py @@ -89,7 +89,7 @@ def _upload_attachment(self, project_code: str, attachment: Attachment) -> Union return response.result except Exception as e: - self.logger.log(f"Error at uploading attachment: {e}", "debug") + self.logger.log(f"Error at uploading attachment: {e}", "error") return None def create_test_run(self, project_code: str, title: str, description: str, plan_id=None, diff --git a/qase-python-commons/src/qase/commons/client/api_v2_client.py b/qase-python-commons/src/qase/commons/client/api_v2_client.py index 0b5ab514..60022141 100644 --- a/qase-python-commons/src/qase/commons/client/api_v2_client.py +++ b/qase-python-commons/src/qase/commons/client/api_v2_client.py @@ -16,6 +16,7 @@ from .api_v1_client import ApiV1Client from .. import Logger from ..exceptions.reporter import ReporterException +from ..models.config.framework import Video, Trace from ..models import Attachment, Result from ..models.config.qaseconfig import QaseConfig from ..models.step import StepType, Step @@ -56,7 +57,11 @@ def _prepare_result(self, project_code: str, result: Result) -> ResultCreate: attached = [] if result.attachments: for attachment in result.attachments: - attached.extend(self._upload_attachment(project_code, attachment)) + if self.__should_skip_attachment(attachment, result): + continue + attach_id = self._upload_attachment(project_code, attachment) + if attach_id: + attached.extend(attach_id) steps = [] for step in result.steps: @@ -142,7 +147,9 @@ def _prepare_step(self, project_code: str, step: Step) -> Dict: if step.attachments: uploaded_attachments = [] for file in step.attachments: - uploaded_attachments.extend(self._upload_attachment(project_code, file)) + attach_id = self._upload_attachment(project_code, file) + if attach_id: + uploaded_attachments.extend(attach_id) prepared_step['execution']['attachments'] = [attach.hash for attach in uploaded_attachments] @@ -154,3 +161,14 @@ def _prepare_step(self, project_code: str, step: Step) -> Dict: except Exception as e: self.logger.log(f"Error at preparing step: {e}", "error") raise ReporterException(e) + + def __should_skip_attachment(self, attachment, result): + if (self.config.framework.playwright.video == Video.failed and + result.execution.status != 'failed' and + attachment.file_name == 'video.webm'): + return True + if (self.config.framework.playwright.trace == Trace.failed and + result.execution.status != 'failed' and + attachment.file_name == 'trace.zip'): + return True + return False