-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from fundakol/xray-report-file
Save XRAY execution report to file
- Loading branch information
Showing
7 changed files
with
167 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
XRAY_TEST_PLAN_ID = '--testplan' | ||
XRAY_EXECUTION_ID = '--execution' | ||
JIRA_CLOUD = '--cloud' | ||
XRAYPATH = '--xraypath' |
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,5 @@ | ||
class XrayError(Exception): | ||
"""Custom exception for Jira XRAY""" | ||
|
||
def __init__(self, message=''): | ||
self.message = message |
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,33 @@ | ||
import json | ||
import logging | ||
from pathlib import Path | ||
|
||
from pytest_xray.exceptions import XrayError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FilePublisher: | ||
|
||
def __init__(self, filepath: str): | ||
self.filepath: Path = Path(filepath) | ||
|
||
def publish(self, data: dict) -> str: | ||
""" | ||
Save results to a file or raise XrayError. | ||
:param data: data to save | ||
:return: file path where data was saved | ||
""" | ||
self.filepath.parent.mkdir(parents=True, exist_ok=True) | ||
try: | ||
with open(self.filepath, 'w', encoding='UTF-8') as file: | ||
json.dump(data, file, indent=2) | ||
except FileNotFoundError as e: | ||
logger.exception(e) | ||
raise XrayError(f'File not found: {self.filepath}') from e | ||
except TypeError as e: | ||
logger.exception(e) | ||
raise XrayError(f'Cannot save data to file: {self.filepath}') from e | ||
else: | ||
return f'{self.filepath}' |
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
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