Skip to content

Commit 0d52622

Browse files
committed
Add examples of allure.dynamic.parameter usages (allure-framework#727)
1 parent 919d3df commit 0d52622

7 files changed

Lines changed: 161 additions & 16 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The repository contains adaptors for Python-based test frameworks.
55
Documentation is available
66
[online](https://docs.qameta.io/allure-report/), also you can get help at
7-
[gitter channel](https://gitter.im/allure-framework/allure-core)
7+
[gitter channel](https://gitter.im/allure-framework/allure-core).
88

99
## Pytest
1010
[![Release
@@ -13,7 +13,9 @@ Status](https://img.shields.io/pypi/v/allure-pytest)](https://pypi.python.org/py
1313

1414
Allure [pytest](http://pytest.org) integration. It's developed as pytest
1515
plugin and distributed via
16-
[pypi](https://pypi.python.org/pypi/allure-pytest)
16+
[pypi](https://pypi.python.org/pypi/allure-pytest).
17+
18+
Examples are available [here](allure-pytest/examples).
1719

1820
## Behave
1921
[![Release

allure-behave/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Allure Behave Formatter
22
=======================
3-
.. image:: https://pypip.in/v/allure-behave/badge.png
3+
.. image:: https://img.shields.io/pypi/v/allure-behave
44
:alt: Release Status
55
:target: https://pypi.python.org/pypi/allure-behave
6-
.. image:: https://pypip.in/d/allure-behave/badge.png
6+
.. image:: https://img.shields.io/pypi/dm/allure-behave
77
:alt: Downloads
88
:target: https://pypi.python.org/pypi/allure-behave
99

allure-pytest/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Allure Pytest Plugin
22
====================
3-
.. image:: https://pypip.in/v/allure-pytest/badge.png
3+
.. image:: https://img.shields.io/pypi/v/allure-pytest
44
:alt: Release Status
55
:target: https://pypi.python.org/pypi/allure-pytest
6-
.. image:: https://pypip.in/d/allure-pytest/badge.png
6+
.. image:: https://img.shields.io/pypi/dm/allure-pytest
77
:alt: Downloads
88
:target: https://pypi.python.org/pypi/allure-pytest
99

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Dynamic parameter
2+
-------------------
3+
4+
It's possible to dynamically add a parameter to a test result:
5+
6+
7+
>>> import allure
8+
9+
>>> def test_dynamic_parameter():
10+
... allure.dynamic.parameter("username", "John Doe")
11+
12+
13+
The parameter name and value are shown in the "Parameters" section of the test
14+
details view. Additionally, the value is shown near the test name in the test
15+
tree view.
16+
17+
18+
Affecting the history of test execution in Allure TestOps
19+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
Parameters also affect how Allure TestOps keeps test history and retry records
22+
across test results. Two test results that differs from each other in a
23+
parameter value are considered as belonging to different test cases, thus
24+
forming separate histories.
25+
26+
This behavior can be changed with ``excluded`` argument:
27+
28+
29+
>>> import allure
30+
... import os
31+
32+
>>> def test_excluded_dynamic_parameter():
33+
... allure.dynamic.parameter("work-dir", os.getcwd(), excluded=True)
34+
35+
36+
Such a parameter isn't taken into account by Allure TestOps when it decides
37+
whether two test results actually belong to a single test case. This is useful
38+
if you want to add environment-related information (such as host names, OS, PID,
39+
paths, versions, etc.) but keep history the same if the information is changed.
40+
41+
42+
Masking a sensitive parameter
43+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
A parameter value can be masked with ``mode`` argument. The masked value is shown
46+
as `******` in the report. This is useful for sensitive parameters like
47+
passwords or key phrases:
48+
49+
50+
>>> import allure
51+
52+
>>> def test_masked_dynamic_parameter():
53+
... allure.dynamic.parameter("password", "qwerty", mode=allure.parameter_mode.MASKED)
54+
55+
56+
.. warning:: Although the value is masked in the report, it is still present in the
57+
test result files (but not in report files, i.e., generated by allure
58+
reporter).
59+
60+
61+
Hiding a parameter from the report
62+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
64+
A parameter can be hidden from the report completely. It still affects the
65+
history of the test case though. This is useful if you want to force Allure
66+
TestOps to distribute otherwise indistinguishable test results across different
67+
test cases:
68+
69+
70+
>>> import allure
71+
... import socket
72+
73+
>>> def test_hidden_dynamic_parameter():
74+
... allure.dynamic.parameter("hostname", socket.gethostname(), mode=allure.parameter_mode.HIDDEN)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""" ./examples/parameter/dynamic_parameter.rst """
2+
3+
from hamcrest import assert_that
4+
from allure_commons_test.report import has_test_case
5+
from allure_commons_test.result import (
6+
has_parameter,
7+
get_parameter_matcher,
8+
with_excluded,
9+
with_mode
10+
)
11+
12+
13+
def test_dynamic_parameter(executed_docstring_path):
14+
assert_that(
15+
executed_docstring_path.allure_report,
16+
has_test_case(
17+
"test_dynamic_parameter",
18+
has_parameter("username", "'John Doe'")
19+
)
20+
)
21+
22+
23+
def test_masked_dynamic_parameter(executed_docstring_path):
24+
assert_that(
25+
executed_docstring_path.allure_report,
26+
has_test_case(
27+
"test_masked_dynamic_parameter",
28+
has_parameter(
29+
"password",
30+
"'qwerty'",
31+
with_mode("masked")
32+
)
33+
)
34+
)
35+
36+
37+
def test_hidden_dynamic_parameter(executed_docstring_path):
38+
assert_that(
39+
executed_docstring_path.allure_report,
40+
has_test_case(
41+
"test_hidden_dynamic_parameter",
42+
get_parameter_matcher(
43+
"hostname",
44+
with_mode("hidden")
45+
)
46+
)
47+
)
48+
49+
50+
def test_excluded_dynamic_parameter(executed_docstring_path):
51+
assert_that(
52+
executed_docstring_path.allure_report,
53+
has_test_case(
54+
"test_excluded_dynamic_parameter",
55+
get_parameter_matcher(
56+
"work-dir",
57+
with_excluded()
58+
)
59+
)
60+
)

allure-python-commons-test/src/result.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,24 @@ def has_step(name, *matchers):
9191
))
9292

9393

94+
def get_parameter_matcher(name, *matchers):
95+
return has_entry(
96+
'parameters',
97+
has_item(
98+
all_of(
99+
has_entry('name', equal_to(name)),
100+
*matchers
101+
)
102+
)
103+
)
104+
105+
94106
def has_parameter(name, value, *matchers):
95-
return has_entry('parameters',
96-
has_item(
97-
all_of(
98-
has_entry('name', equal_to(name)),
99-
has_entry('value', equal_to(value)),
100-
*matchers
101-
)
102-
))
107+
return get_parameter_matcher(
108+
name,
109+
has_entry('value', equal_to(value)),
110+
*matchers
111+
)
103112

104113

105114
def doesnt_have_parameter(name):

allure-robotframework/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Allure Robot Framework Listener
22
===============================
3-
.. image:: https://pypip.in/v/allure-robotframework/badge.png
3+
.. image:: https://img.shields.io/pypi/v/allure-robotframework
44
:alt: Release Status
55
:target: https://pypi.python.org/pypi/allure-robotframework
6-
.. image:: https://pypip.in/d/allure-robotframework/badge.png
6+
.. image:: https://img.shields.io/pypi/dm/allure-robotframework
77
:alt: Downloads
88
:target: https://pypi.python.org/pypi/allure-robotframework
99

0 commit comments

Comments
 (0)