Skip to content
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
37 changes: 30 additions & 7 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os

from pathlib import Path
from platform import system
from tempfile import mkstemp
from textwrap import dedent

from invoke import run, task


CURDIR = Path.cwd()
SRCPATH = CURDIR / 'src'
UNIT_TESTS = CURDIR / 'tests'
DUMMYHANDLERS = UNIT_TESTS / 'resources' / 'my_dummy_handlers'

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

def _setup_atest():
_, tempconf = mkstemp()
with open(tempconf, 'w') as f:
f.write('''dummy_handler_metadata:
handler: MyDummyMetadataHandler
keyword: run_metadata_dummy_handler
tags: oxygen-metadata''')
return (tempconf,
os.pathsep.join([str(SRCPATH),
str(DUMMYHANDLERS)]))

@task(help={
'rf': 'Additional command-line arguments for Robot Framework as '
'single string. E.g: invoke atest --rf "--name my_suite"'
})
def atest(context, rf=''):
run(f'robot '
f'--pythonpath {str(SRCPATH)} '
f'--dotted '
f'{rf} '
f'--listener oxygen.listener '
f'{str(CURDIR / "tests" / "atest")}',
pty=(not system() == 'Windows'))
tempconf, pythonpath = _setup_atest()
run(f'python -m oxygen --add-config {tempconf}',
env={'PYTHONPATH': pythonpath})
try:
run(f'robot '
f'--pythonpath {str(SRCPATH)} '
f'--pythonpath {str(DUMMYHANDLERS)} '
f'--dotted '
f'{rf} '
f'--listener oxygen.listener '
f'{str(CURDIR / "tests" / "atest")}',
pty=(not system() == 'Windows'))
finally:
run('python -m oxygen --reset-config', env={'PYTHONPATH': pythonpath})

@task
def test(context):
Expand Down
9 changes: 9 additions & 0 deletions tests/atest/metadata.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*** Settings ***
Library oxygen.OxygenLibrary
Metadata RF suite This metadata comes from the suite file itself

*** Test Cases ***
Metadata returned by handler should be visible
[Documentation] This test is replaced with fix results that have metadata in them
Run Metadata Dummy Handler doesentmatter

21 changes: 21 additions & 0 deletions tests/resources/my_dummy_handlers/dummy_handler_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from oxygen import BaseHandler

class MyDummyMetadataHandler(BaseHandler):
def run_metadata_dummy_handler(self, result_file):
return result_file

def parse_results(self, result_file):
return {
'name': 'Minimal Suite',
'metadata': {
'Main-level metadata': 'This should come *from handler*'
},
'suites': [{
'name': 'Minimal Subsuite',
'metadata': { 'Sub-level metadata': '_Inner_ metadata' },
'tests': [{
'name': 'Minimal TC',
'keywords': [{ 'name': 'someKeyword', 'pass': True }]
}]
}]
}