Skip to content

Commit 5d70867

Browse files
authored
Merge pull request #48 from eficode/feat/rf-metadata-atest
Add acceptance tests for RF metadata coming from handlers
2 parents 98c1110 + 3a47454 commit 5d70867

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

tasks.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import os
2+
13
from pathlib import Path
24
from platform import system
5+
from tempfile import mkstemp
6+
from textwrap import dedent
37

48
from invoke import run, task
59

610

711
CURDIR = Path.cwd()
812
SRCPATH = CURDIR / 'src'
913
UNIT_TESTS = CURDIR / 'tests'
14+
DUMMYHANDLERS = UNIT_TESTS / 'resources' / 'my_dummy_handlers'
1015

1116
# If you want colored output for the tasks, use `run()` with `pty=True`
1217
# Not on Windows, though -- it'll fail if you have `pty=True`
@@ -48,18 +53,36 @@ def coverage(context):
4853
pty=(not system() == 'Windows'))
4954
run('coverage html')
5055

56+
def _setup_atest():
57+
_, tempconf = mkstemp()
58+
with open(tempconf, 'w') as f:
59+
f.write('''dummy_handler_metadata:
60+
handler: MyDummyMetadataHandler
61+
keyword: run_metadata_dummy_handler
62+
tags: oxygen-metadata''')
63+
return (tempconf,
64+
os.pathsep.join([str(SRCPATH),
65+
str(DUMMYHANDLERS)]))
66+
5167
@task(help={
5268
'rf': 'Additional command-line arguments for Robot Framework as '
5369
'single string. E.g: invoke atest --rf "--name my_suite"'
5470
})
5571
def atest(context, rf=''):
56-
run(f'robot '
57-
f'--pythonpath {str(SRCPATH)} '
58-
f'--dotted '
59-
f'{rf} '
60-
f'--listener oxygen.listener '
61-
f'{str(CURDIR / "tests" / "atest")}',
62-
pty=(not system() == 'Windows'))
72+
tempconf, pythonpath = _setup_atest()
73+
run(f'python -m oxygen --add-config {tempconf}',
74+
env={'PYTHONPATH': pythonpath})
75+
try:
76+
run(f'robot '
77+
f'--pythonpath {str(SRCPATH)} '
78+
f'--pythonpath {str(DUMMYHANDLERS)} '
79+
f'--dotted '
80+
f'{rf} '
81+
f'--listener oxygen.listener '
82+
f'{str(CURDIR / "tests" / "atest")}',
83+
pty=(not system() == 'Windows'))
84+
finally:
85+
run('python -m oxygen --reset-config', env={'PYTHONPATH': pythonpath})
6386

6487
@task
6588
def test(context):

tests/atest/metadata.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Settings ***
2+
Library oxygen.OxygenLibrary
3+
Metadata RF suite This metadata comes from the suite file itself
4+
5+
*** Test Cases ***
6+
Metadata returned by handler should be visible
7+
[Documentation] This test is replaced with fix results that have metadata in them
8+
Run Metadata Dummy Handler doesentmatter
9+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from oxygen import BaseHandler
2+
3+
class MyDummyMetadataHandler(BaseHandler):
4+
def run_metadata_dummy_handler(self, result_file):
5+
return result_file
6+
7+
def parse_results(self, result_file):
8+
return {
9+
'name': 'Minimal Suite',
10+
'metadata': {
11+
'Main-level metadata': 'This should come *from handler*'
12+
},
13+
'suites': [{
14+
'name': 'Minimal Subsuite',
15+
'metadata': { 'Sub-level metadata': '_Inner_ metadata' },
16+
'tests': [{
17+
'name': 'Minimal TC',
18+
'keywords': [{ 'name': 'someKeyword', 'pass': True }]
19+
}]
20+
}]
21+
}

0 commit comments

Comments
 (0)