Giter Club home page Giter Club logo

junit-report's Introduction

Junit-Report

This Python package adds more control to your tests by decorating your functions and pytest fixtures and exporting them as JUnit xml.

Table of contents

Installation

pip install junit-report

Usage

import pytest

from junit_report import JunitTestSuite, JunitTestCase, JunitFixtureTestCase

class TestSomeThing:

    @pytest.fixture
    @JunitFixtureTestCase()
    def my_fixture(self):
        # do stuff ..
        
        @JunitTestCase()
        def nested_case():
          pass
        
        yield nested_case
        
    @JunitTestCase()
    def my_first_test_case(self):
        pass
    
    @JunitTestCase()
    def my_second_test_case(self, name: str):
        raise ValueError(f"Invalid name {name}")
    
    @JunitTestSuite()
    def test_suite(self, my_fixture):
        my_fixture()
        self.my_first_test_case()
        self.my_second_test_case("John")

Output

<?xml version="1.0" ?>
<testsuites disabled="0" errors="0" failures="1" tests="4" time="0.000301361083984375">
	<testsuite disabled="0" errors="0" failures="1" name="TestSomeThing_test_suite" skipped="0" tests="4" time="0.000301361083984375">
		<testcase name="my_fixture" time="0.000163" classname="TestSomeThing" class="fixture"/>
		<testcase name="nested_case" time="0.000034" classname="module_name.test" class="function"/>
		<testcase name="my_first_test_case" time="0.000017" classname="TestSomeThing" class="function"/>
		<testcase name="my_second_test_case" time="0.000087" classname="TestSomeThing" class="function">
			<failure type="ValueError" message="Invalid name John">Traceback (most recent call last): ... ValueError: Invalid name John</failure>
		</testcase>
	</testsuite>
</testsuites>

OS parameters used for configuration

Variable Description
JUNIT_REPORT_DIR Reports directory where the reports will be extracted. If it does not exist - create it.

junit-report's People

Contributors

eliorerz avatar omertuc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

omertuc

junit-report's Issues

JunitFixtureTestSuite return wrong value on nested function

If decorating nested function with JunitFixtureTestSuite it return generator instead of the actual value.

class TestJunitNestedTestCase(TestJunitNestedBaseTestCase):
    @pytest.fixture(scope="function")
    @JunitFixtureTestCase()
    def get_some_fixture(self):
        @JunitFixtureTestCase()  # Error but not raised 
        def get_my_fixture():
            return "Test"

        yield get_my_fixture

    @JunitTestSuite(REPORT_DIR)
    def test_suite_nested_fixture(self, get_some_fixture):
        self.other_test_case()
        get_some_fixture().get_my_fixture()  # Bug ->  get_my_fixture() returns generator
        self.third_test_case()

TestCase after yield happens after suite exported

class TestJunitNestedTestCase(TestJunitNestedBaseTestCase):
    @JunitTestCase() 
    def after_yield_test_case(self):
        return "Test"

    @pytest.fixture(scope="function")
    @JunitFixtureTestCase()
    def fixture(self):

        yield 
        
       self.after_yield_test_case()  # Only occurs after a JUnit report is exported

    @JunitTestSuite(REPORT_DIR)
    def test_suite_nested_fixture(self, fixture):
        self.other_test_case()
        self.third_test_case()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.