Skip to content

Commit 88ff002

Browse files
author
Matej Cotman
committed
feat(oxygen): do not fail on robot suites that do not use Oxygen
1 parent 8c3def1 commit 88ff002

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/oxygen/oxygen.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from robot.api import ExecutionResult, ResultVisitor, ResultWriter
1010
from robot.libraries.BuiltIn import BuiltIn
11+
from robot.errors import DataError
1112
from yaml import load, FullLoader
1213

1314
from .config import CONFIG_FILE
@@ -85,9 +86,12 @@ def __init__(self):
8586
self.run_time_data = {}
8687

8788
def end_test(self, name, attributes):
88-
lib = BuiltIn().get_library_instance('oxygen.OxygenLibrary')
89-
if lib:
89+
try:
90+
lib = BuiltIn()._get_context().namespace.get_library_instance(
91+
'oxygen.OxygenLibrary')
9092
self.run_time_data[attributes['longname']] = lib.data
93+
except DataError as _:
94+
pass
9195

9296
def output_file(self, path):
9397
result = ExecutionResult(path)

tests/atest/test_with_import.robot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*** Settings ***
2+
Library oxygen.OxygenLibrary
3+
Library OperatingSystem
4+
5+
*** Variables ***
6+
${JUNIT XML FILE}= ${CURDIR}${/}..${/}resources${/}junit-single-testsuite.xml
7+
8+
*** Test Cases ***
9+
Oxygen's unit test with dynamic import
10+
Import Library oxygen.OxygenLibrary
11+
Run JUnit ${JUNIT XML FILE}
12+
... echo Run JUnit Dynamically Imported
13+
14+
Oxygen's unit test with global import
15+
Run JUnit ${JUNIT XML FILE}
16+
... echo Run JUnit Globally Imported

tests/atest/test_without_import.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Test Cases ***
2+
Oxygen's unit test without import
3+
Log Some text
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from tasks import SRCPATH
2+
from unittest import TestCase
3+
from subprocess import run
4+
5+
from ..helpers import RESOURCES_PATH
6+
7+
8+
class TestOptionalOxygenLibrary(TestCase):
9+
10+
def test_junit_works_on_cli(self):
11+
run(f'robot --pythonpath {str(SRCPATH)}'
12+
f'--dotted '
13+
f'--listener oxygen.listener '
14+
f'{str(RESOURCES_PATH / "dummy_tests")}',
15+
check=True,
16+
shell=True)

0 commit comments

Comments
 (0)