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
Metadata
Release files for allure-subtests 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| allure_subtests-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for allure_subtests-0.1.9-py3-none-any.whl |
Release files / allure_subtests-0.1.9-py3-none-any.whl
| Download URL | allure_subtests-0.1.9-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de2b261d0213aff9c209fa25aa68f96505203327d96fe1eed99b4f242bf31589
|
|
BLAKE2b-256 checksum How to use checksums |
59d59c14a9322f1422df915da0f19a5f5e0e0f7db4531d06de14ea1b093ad006
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for allure-subtests 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.