Skip to content

Conversation

@ubaumann
Copy link
Contributor

Allowing to customize reports like junit xml without hard code it in Nuts

@ubaumann
Copy link
Contributor Author

I want to allow uses to extend reports like junit without hard code it in nuts

As a PoC I created the following conftest.py

import pytest

@pytest.hookimpl(tryfirst=True)
def pytest_nuts_single_result(request, nuts_ctx, result):
    test_extras = nuts_ctx.nuts_parameters.get("test_extras", {})
    for p_name, p_value in test_extras.get("properties", {}).items():
        request.node.user_properties.append((p_name, p_value))

And with the test file:

- test_module: tests.showcase.showcase_expanse
  test_class: TestExpanseCrew
  test_extras:
    properties:
      demo: urs
      demo2: 1
  test_data:
    - ship: rocinante
      name: "naomi nagata"
      role: engineer
      origin: belter

pytest tests/showcase_test/test-expanse.yaml --junit-xml=mydemo.xml generates:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
    <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="15" time="0.050"
        timestamp="2024-05-27T08:43:13.722041" hostname="codespaces-d1d96a">
        <testcase classname="tests.showcase_test.test-expanse.yaml.TestExpanseCrew"
            name="test_name[0]" file="tests/showcase/showcase_expanse.py" line="79" time="0.000">
            <properties>
                <property name="demo" value="urs" />
                <property name="demo2" value="1" />
            </properties>
        </testcase>

@The-Compiler before I continue, is this an acceptable approach?

@ubaumann ubaumann self-assigned this May 27, 2024
@ubaumann ubaumann marked this pull request as draft May 27, 2024 09:03
@The-Compiler
Copy link
Contributor

Seems fine by me!

@ubaumann ubaumann requested a review from marcom4rtinez May 27, 2024 18:51
@ubaumann ubaumann marked this pull request as ready for review May 27, 2024 18:52
Copy link
Contributor

@marcom4rtinez marcom4rtinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubaumann ubaumann merged commit fdc42cd into main May 28, 2024
@ubaumann ubaumann deleted the hook_pytest_nuts_single_result branch May 28, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants