-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: ability to attach attachments to step implementations
Implement the `qase.attach()` method which adds attachments to a step.
- Loading branch information
Showing
5 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "qase-robotframework" | ||
version = "3.1.0b2" | ||
version = "3.1.0b3" | ||
description = "Qase Robot Framework Plugin" | ||
readme = "README.md" | ||
authors = [{name = "Qase Team", email = "[email protected]"}] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Union, Tuple | ||
from qase.commons import QaseUtils | ||
import mimetypes | ||
from qase.commons.models.attachment import Attachment | ||
|
||
from .plugin import QaseRuntimeSingleton | ||
|
||
|
||
class qase: | ||
"""Class with decorators for robotframework""" | ||
|
||
@staticmethod | ||
def attach( | ||
self, *files: Union[str, Tuple[str, str], Tuple[bytes, str, str]] | ||
): | ||
""" | ||
Attach files to test results | ||
`files` could be: | ||
- str - only `filepath` | ||
- str, str - `filepath` and `mime-type` for it | ||
- bytes, str, str - `source` data, `mime-type` and `filename` | ||
>>> from src.client.models import MimeTypes | ||
... qase.attach( | ||
... (driver.get_screenshot_as_png(), MimeTypes.PNG, "page.png") | ||
... ) | ||
""" | ||
for file in files: | ||
filename = None | ||
content = None | ||
file_path = None | ||
|
||
if isinstance(file, tuple): | ||
if len(file) == 2: | ||
file_path, mime = file | ||
filename = QaseUtils.get_filename(file_path) | ||
else: | ||
content, mime, filename = file | ||
elif isinstance(file, str): | ||
file_path = file | ||
mime = mimetypes.guess_type(file)[0] | ||
filename = QaseUtils.get_filename(file_path) | ||
|
||
attachment = Attachment(file_name=filename, content=content, mime_type=mime, file_path=file_path) | ||
QaseRuntimeSingleton.get_instance().add_attachment(attachment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from qase.commons.models.runtime import Runtime | ||
|
||
|
||
class QaseRuntimeSingleton: | ||
_instance: Runtime = None | ||
|
||
@staticmethod | ||
def get_instance() -> Runtime: | ||
""" Static access method""" | ||
if QaseRuntimeSingleton._instance is None: | ||
QaseRuntimeSingleton._instance = Runtime() | ||
return QaseRuntimeSingleton._instance | ||
|
||
def __init__(self): | ||
""" Virtually private constructor""" | ||
raise Exception("Use get_instance()") |