Skip to main content

Support teardown_subtest, default is None

Project description

allure-subtests

Introduction

Allure-subtests is a Python library that can generate subtest results in an Allure report.

Usage

I run below code under:

  • Python3.12
from loguru import logger
import allure


class TestSubTest:
    def test_demo(self, allure_subtests):
        for i in range(3):
            with allure_subtests.test(subtest_name=f"custom message:{i=}"):
                allure.dynamic.parent_suite('changed parent suite')
                logger.info(f'test {i=}')
                assert i % 2 != 0

                if i == 2:
                    raise ValueError(f'custom error {i=}')

please see tests dir for more examples

Why do I need this?

If we want to parameterize test cases, we have 2 ways: pytest parametrize or pytest-subtests

pytest parametrize:

demo like below:

import pytest
from loguru import logger

@pytest.mark.parametrize('i', range(3))
def test_parametrize(i):
    logger.info(f'test {i=}')

There are some disadvantages of this way:

  • the 2nd parameter in pytest.mark.parametrize is a function, it will execute when module import, even test is not executed, if it is complex and time waste, will need a long time
  • pytest.mark.parametrize can only pass simple data type to the test function, it is a little hard to use complex data type and do complex operation

pytest-subtests

use pytest-subtests in https://pypi.org/project/pytest-subtests/

I find there is disadvantage in this way:

  • It is not compatible with Allure, it will generate an Allure report with no subtest results

I want some ways both have the advantages of pytest-subtests and allure.

So this library is born based on pytest-subtests and allure.

ChangeLog

  • 0.1.4
    • support allure.dynamic.parent_suite, suite, sub_suite...
  • 0.1.5
    • support teardown_subtest, default is None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

allure_subtests-0.1.5-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page