Skip to main content

update readme demo according to code change

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=}')

    def test_teardown(self, allure_subtests):
        def teardown_subtest(subtest_name: str, result: bool):
            logger.info('teardown_sub_test_result: {}, result: {}', subtest_name, result)
            pass

        for i in range(3):
            with allure_subtests.test(subtest_name=f"custom message:{i=}", teardown_subtest=teardown_subtest):
                allure.dynamic.parent_suite('This is teardown demo')
                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

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
  • 0.1.7
    • fix subtest execute time always 0s
  • 0.1.8
    • add test result parameter in tear down subtest

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.9-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file allure_subtests-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for allure_subtests-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 de2b261d0213aff9c209fa25aa68f96505203327d96fe1eed99b4f242bf31589
MD5 fa5cfb5ede587e12b945242fb1baf4b6
BLAKE2b-256 59d59c14a9322f1422df915da0f19a5f5e0e0f7db4531d06de14ea1b093ad006

See more details on using hashes here.

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