From b70b3868b5a1b0d142229b1a25f69d8d5872023a Mon Sep 17 00:00:00 2001 From: Tattoo Date: Tue, 31 Oct 2023 12:18:01 +0200 Subject: [PATCH] Add acceptance tests for RF metadata coming from handlers Complements #40 --- tasks.py | 35 +++++++++++++++---- tests/atest/metadata.robot | 9 +++++ .../dummy_handler_metadata.py | 21 +++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 tests/atest/metadata.robot create mode 100644 tests/resources/my_dummy_handlers/dummy_handler_metadata.py diff --git a/tasks.py b/tasks.py index 0df05d5..15d6beb 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 @@ -48,18 +52,35 @@ 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(UNIT_TESTS / 'resources' / 'my_dummy_handlers')])) + @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 {pythonpath} ' + 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 }] + }] + }] + }