diff --git a/tasks.py b/tasks.py index 0df05d5..71e3d51 100644 --- a/tasks.py +++ b/tasks.py @@ -1,5 +1,9 @@ +import os + from pathlib import Path from platform import system +from tempfile import mkstemp +from textwrap import dedent from invoke import run, task @@ -7,6 +11,7 @@ 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` @@ -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): diff --git a/tests/atest/metadata.robot b/tests/atest/metadata.robot new file mode 100644 index 0000000..a69a55e --- /dev/null +++ b/tests/atest/metadata.robot @@ -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 + diff --git a/tests/resources/my_dummy_handlers/dummy_handler_metadata.py b/tests/resources/my_dummy_handlers/dummy_handler_metadata.py new file mode 100644 index 0000000..ca29a48 --- /dev/null +++ b/tests/resources/my_dummy_handlers/dummy_handler_metadata.py @@ -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 }] + }] + }] + }