Skip to content

Commit 576fce1

Browse files
authored
rft allure-pytest self testing (fixes #292 via #354)
1 parent ae9aa91 commit 576fce1

File tree

180 files changed

+3145
-4065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+3145
-4065
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Attachments
2+
-----------
3+
4+
Reports can display many different types of provided attachments that can complement a test, step or fixture result.
5+
Attachments can be created either with invocation of ``allure.attach(body, name, attachment_type, extension):``
6+
7+
``body`` - raw content to be written into the file.
8+
``name`` - a string with name of the file
9+
``attachment_type`` - one of the allure.attachment_type values
10+
``extension`` - is provided will be used as an extension for the created file.
11+
12+
>>> import allure
13+
14+
>>> def test_attach_body_with_default_kwargs():
15+
... allure.attach("Some content in plain text")
16+
17+
>>> def test_attach_body():
18+
... xml_content = """<?xml version="1.0" encoding="UTF-8"?>
19+
... <tag>
20+
... <inside>...</inside>
21+
... </tag>
22+
... """
23+
... allure.attach(xml_content, name='some attachment name', attachment_type=allure.attachment_type.XML)
24+
...
25+
... allure.attach("Some content in plain text")
26+
27+
28+
or ``allure.attach.file(source, name, attachment_type, extension)``:
29+
``source`` - a string containing path to the file.
30+
(other arguments are the same)
31+
32+
>>> def test_attach_file():
33+
...
34+
... allure.attach.file(__file__) # this file path
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Attachment in fixtures
2+
----------------------
3+
4+
Attachments are shown in the context of a test entity they belong to.
5+
6+
You can attach some context from fixture:
7+
8+
>>> import pytest
9+
>>> import allure
10+
11+
>>> @pytest.fixture
12+
... def fixture_with_attachment():
13+
... allure.attach("Fixture context")
14+
15+
>>> def test_fixture_attachment(fixture_with_attachment):
16+
... pass
17+
18+
19+
or fixture finalizer:
20+
21+
>>> import pytest
22+
>>> import allure
23+
24+
>>> @pytest.fixture
25+
... def fixture_with_attachment_in_finalizer(request):
26+
... def finalizer():
27+
... allure.attach(__file__)
28+
... request.addfinalizer(finalizer)
29+
30+
>>> def test_fixture_finalizer_attachment(fixture_with_attachment_in_finalizer):
31+
... pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Attachment in step
2+
------------------
3+
4+
Attachment usage for steps make your test more clear.
5+
6+
>>> import pytest
7+
>>> import allure
8+
9+
>>> @allure.step
10+
... def step_with_attachment():
11+
... allure.attach("hello there")
12+
13+
>>> def test_step_with_attachment():
14+
... step_with_attachment()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Description
2+
-----------
3+
4+
You can add a detailed description for tests to provide as much context to the report reader as you want. This can be
5+
done in several ways: you can add a @allure.description decorator providing a description string or you can use
6+
``@allure.description_html`` to provide some HTML to be rendered in the 'Description' section of a test case.
7+
8+
>>> import allure
9+
10+
>>> @allure.description("""Test description""")
11+
... def test_description():
12+
... pass
13+
14+
15+
>>> @allure.description_html("""<h1>Html test description</h1>""")
16+
... def test_description_html():
17+
... pass
18+
19+
20+
Alternatively description will be simply picked up from the docstring of a test method.
21+
22+
>>> def test_docstring_description():
23+
... """ Docstring """
24+
25+
26+
>>> def test_unicode_docstring_description():
27+
... """ Докстринг в юникоде """
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Dynamic description
2+
-------------------
3+
4+
Also descriptions can be dynamically updated from within test body using allure.dynamic.description.
5+
6+
7+
>>> import allure
8+
9+
>>> @allure.description("Initial description")
10+
... def test_dynamic_description():
11+
... allure.dynamic.description("Actual description")
12+
13+
>>> @allure.description_html("<h1>Initial HTML description</h1>")
14+
... def test_dynamic_description_html():
15+
... allure.dynamic.description_html("<p>Actual HTML description</p>")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Test title
2+
----------
3+
4+
Test titles can be made more readable with special @allure.title decorator.
5+
Titles support placeholders for arguments.
6+
7+
>>> import pytest
8+
>>> import allure
9+
10+
11+
>>> @allure.title("A some test title")
12+
... def test_display_name():
13+
... pass
14+
15+
16+
>>> @allure.title("A some test title with param {param}")
17+
... @pytest.mark.parametrize('param', [False])
18+
... def test_display_name_template(param):
19+
... assert param
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Dynamic test title
2+
------------------
3+
4+
>>> import allure
5+
6+
7+
>>> @allure.title("A some test tile")
8+
>>> def test_dynamic_display_name():
9+
>>> allure.dynamic.title("It is renamed test")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BDD labels
2+
----------
3+
4+
There are two decorators: @allure.feature and @allure.story to mark your tests according to Feature/Story breakdown
5+
specific to your project
6+
7+
>>> import allure
8+
9+
10+
>>> @allure.epic("My epic")
11+
... @allure.feature("My feature")
12+
... @allure.story("My story")
13+
... def test_single_bdd_label():
14+
... pass
15+
16+
17+
>>> @allure.epic("My epic", "Another epic")
18+
... @allure.feature("My feature", "Another feature", "One more feature")
19+
... @allure.story("My story", "Alternative story")
20+
... def test_multiple_bdd_label():
21+
... pass
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Dynamic BDD labels
2+
------------------
3+
4+
>>> import allure
5+
>>> import pytest
6+
7+
>>> @allure.feature('first feature')
8+
... def test_dynamic_feature():
9+
... allure.dynamic.feature('second feature')
10+
11+
>>> @pytest.mark.parametrize('feature', ['first feature', 'second feature'])
12+
... def test_parametrized_dynamic_feature(feature):
13+
... allure.dynamic.feature(feature)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Selecting tests by BDD label
2+
----------------------------
3+
4+
You can use following commandline options to specify different sets of tests to execute passing a list of
5+
comma-separated values:
6+
7+
--allure-epics
8+
--allure-features
9+
--allure-stories
10+
11+
There are some tests marked with BDD labels:
12+
13+
>>> import allure
14+
15+
>>> @allure.epic("My Epic")
16+
... @allure.feature("My Feature")
17+
... @allure.story("My Story")
18+
... def test_with_epic_feature_story():
19+
... pass
20+
21+
22+
>>> @allure.epic("My Epic")
23+
... @allure.feature("My Feature")
24+
... def test_with_epic_feature():
25+
... pass
26+
27+
28+
>>> @allure.epic("My Epic")
29+
... def test_with_epic():
30+
... pass
31+
32+
33+
>>> @allure.epic("Another Epic")
34+
... @allure.feature("Another Feature")
35+
... @allure.story("Another Story")
36+
... def test_with_another_epic_feature_story():
37+
... pass
38+
39+
If you run ``pytest`` with following options: ``$ pytest tests.py --allure-epics=My Epic --alluredir=./report`` first
40+
three tests will be runned.
41+
42+
And with next options: ``$ pytest tests.py --allure-stories=My Story, Another Story --alluredir=./report`` it will
43+
run just are first and last test.

0 commit comments

Comments
 (0)