Skip to content

Do not throw error on suites that do not have need for oxygen #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/oxygen/oxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from robot.api import ExecutionResult, ResultVisitor, ResultWriter
from robot.libraries.BuiltIn import BuiltIn
from robot.errors import DataError
from yaml import load, FullLoader

from .config import CONFIG_FILE
Expand Down Expand Up @@ -85,9 +86,13 @@ def __init__(self):
self.run_time_data = {}

def end_test(self, name, attributes):
lib = BuiltIn().get_library_instance('oxygen.OxygenLibrary')
if lib:
self.run_time_data[attributes['longname']] = lib.data
try:
lib = BuiltIn()._get_context().namespace.get_library_instance(
'oxygen.OxygenLibrary')
if lib:
self.run_time_data[attributes['longname']] = lib.data
except DataError as _:
pass

def output_file(self, path):
result = ExecutionResult(path)
Expand Down
16 changes: 16 additions & 0 deletions tests/atest/test_with_import.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*** Settings ***
Library oxygen.OxygenLibrary
Library OperatingSystem

*** Variables ***
${JUNIT XML FILE}= ${CURDIR}${/}..${/}resources${/}junit-single-testsuite.xml

*** Test Cases ***
Oxygen's unit test with dynamic import
Import Library oxygen.OxygenLibrary
Run JUnit ${JUNIT XML FILE}
... echo Run JUnit Dynamically Imported

Oxygen's unit test with global import
Run JUnit ${JUNIT XML FILE}
... echo Run JUnit Globally Imported
3 changes: 3 additions & 0 deletions tests/atest/test_without_import.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** Test Cases ***
Oxygen's unit test without import
Log Some text
15 changes: 9 additions & 6 deletions tests/utest/oxygen/test_oxygen_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ def test_listener_api_version_is_not_changed_accidentally(self):
self.assertEqual(self.listener.ROBOT_LISTENER_API_VERSION, 2)

def mock_lib_instance(self, mock_builtin, return_value):
m = Mock()
m.get_library_instance.return_value = return_value
mock_builtin.return_value = m
return m
m_builtin = Mock()
m_get_context = Mock()
m_builtin._get_context.return_value = m_get_context
m_get_context.namespace.get_library_instance.return_value = \
return_value
mock_builtin.return_value = m_builtin
return m_builtin

@patch('oxygen.oxygen.BuiltIn')
def test_end_test_when_library_was_not_used(self, mock_builtin):
m = self.mock_lib_instance(mock_builtin, None)

self.listener.end_test('foo', {})

m.get_library_instance.assert_called_once_with('oxygen.OxygenLibrary')
m._get_context().namespace.get_library_instance.assert_called_once_with('oxygen.OxygenLibrary')
self.assertEqual(self.listener.run_time_data, {})

@patch('oxygen.oxygen.BuiltIn')
Expand All @@ -33,7 +36,7 @@ def test_end_test_when_library_was_used(self, mock_builtin):

self.listener.end_test('oxygen.OxygenLibrary', {'longname': 'hello'})

m.get_library_instance.assert_called_once_with('oxygen.OxygenLibrary')
m._get_context().namespace.get_library_instance.assert_called_once_with('oxygen.OxygenLibrary')
self.assertEqual(self.listener.run_time_data,
{'hello': ('I do not have a solution, but I do '
'admire the problem')})