Skip to content

Commit 86cff25

Browse files
authored
Refactor tests to use pytest as a test runner for all the packages (#732)
1 parent 919d3df commit 86cff25

File tree

376 files changed

+10315
-6542
lines changed

Some content is hidden

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

376 files changed

+10315
-6542
lines changed

.flake8

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
max-line-length = 120
33
import-order-style = google
44
inline-quotes = "
5+
exclude =
6+
./tests/allure_behave/acceptance/**/test-data/**
7+
./tests/allure_behave/acceptance/behave_support/background/background_steps.py
8+
per-file-ignores =
9+
./allure-python-commons/src/model2.py:A003

.github/workflows/build.yaml

+16-18
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,32 @@ jobs:
2020
- allure-behave/**
2121
- allure-python-commons/**
2222
- allure-python-commons-test/**
23+
- tests/*.py
24+
- tests/allure_behave/**
2325
allure-nose2:
2426
- allure-nose2/**
2527
- allure-python-commons/**
2628
- allure-python-commons-test/**
29+
- tests/*.py
30+
- tests/allure_nose2/**
2731
allure-pytest:
2832
- allure-pytest/**
2933
- allure-python-commons/**
3034
- allure-python-commons-test/**
35+
- tests/*.py
36+
- tests/allure_pytest/**
3137
allure-pytest-bdd:
3238
- allure-pytest-bdd/**
3339
- allure-python-commons/**
3440
- allure-python-commons-test/**
41+
- tests/*.py
42+
- tests/allure_pytest_bdd/**
3543
allure-robotframework:
3644
- allure-robotframework/**
3745
- allure-python-commons/**
3846
- allure-python-commons-test/**
47+
- tests/*.py
48+
- tests/allure_robotframework/**
3949
allure-python-commons: allure-python-commons/**
4050
allure-python-commons-test: allure-python-commons-test/**
4151
@@ -63,9 +73,6 @@ jobs:
6373
runs-on: ubuntu-latest
6474
needs: [commons, changes]
6575
if: ${{ needs.changes.outputs.packages != '[]' }}
66-
strategy:
67-
matrix:
68-
package: ${{ fromJSON(needs.changes.outputs.packages) }}
6976
steps:
7077
- uses: actions/checkout@v3
7178

@@ -74,24 +81,14 @@ jobs:
7481
with:
7582
python-version: "3.11"
7683

77-
- name: Get commons from cache
78-
id: commons
79-
uses: actions/cache@v3
80-
with:
81-
path: dist/
82-
key: commons-${{ github.sha }}
83-
84-
- name: Install packages
85-
run: pip install dist/allure-python-commons*.tar.gz &&
86-
pip install ./${{ matrix.package }} &&
87-
pip install -r ${{ matrix.package }}/requirements.txt
84+
- name: Install linting packages
85+
run: pip install -r ./requirements/linting.txt
8886

89-
- name: Static check ${{ matrix.package }}
90-
working-directory: ${{ matrix.package }}
87+
- name: Linting the codebase
9188
run: poe linter
9289

9390
build:
94-
name: Build package
91+
name: Test package
9592
runs-on: ubuntu-latest
9693
needs: [linters, commons, changes]
9794
if: ${{ needs.changes.outputs.packages != '[]' }}
@@ -120,7 +117,8 @@ jobs:
120117
- name: Install packages
121118
run: pip install dist/allure-python-commons*.tar.gz &&
122119
pip install ./${{ matrix.package }} &&
123-
pip install -r ${{ matrix.package }}/requirements.txt
120+
pip install -r ./requirements/testing.txt &&
121+
pip install -r ./requirements/testing/${{ matrix.package }}.txt
124122

125123
- name: Test ${{ matrix.package }}
126124
working-directory: ${{ matrix.package }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
*.egg-info
99

1010
*/build
11-
*/dist
11+
*/dist
12+
13+
/.allure-report
14+
/.allure-results

README.md

+12-6
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+
[Usage examples](/allure-pytest/examples).
1719

1820
## Behave
1921
[![Release
@@ -23,7 +25,9 @@ Status](https://img.shields.io/pypi/v/allure-behave)](https://pypi.python.org/py
2325
Allure [behave](https://behave.readthedocs.io/en/latest/) integration.
2426
Just external formatter that produce test results in allure2 format.
2527
This package is available on
26-
[pypi](https://pypi.python.org/pypi/allure-behave)
28+
[pypi](https://pypi.python.org/pypi/allure-behave).
29+
30+
[Usage examples](/allure-behave/examples).
2731

2832
## Robot Framework
2933
[![Release
@@ -33,9 +37,11 @@ Status](https://img.shields.io/pypi/v/allure-robotframework)](https://pypi.pytho
3337
Allure [RobotFramework](http://robotframework.org/) integration. This
3438
integration is a
3539
[Listener](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-interface\))
36-
and does not require changing autotests
40+
and does not require changing autotests.
41+
42+
[Read more ...](/allure-robotframework/README.rst).
3743

38-
[Read more ...](/allure-robotframework/README.rst)
44+
[Usage examples](/allure-robotframework/examples).
3945

4046
## Pytest-BDD
4147

@@ -45,7 +51,7 @@ Status](https://img.shields.io/pypi/v/allure-pytest-bdd)](https://pypi.python.or
4551

4652
Allure [pytest-bdd](http://pytest.org) integration. It's developed as
4753
pytest plugin and distributed via
48-
[pypi](https://pypi.python.org/pypi/allure-pytest-bdd)
54+
[pypi](https://pypi.python.org/pypi/allure-pytest-bdd).
4955

5056
## Nose2
5157
[![Release

allure-behave/README.rst

+8-3
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

@@ -37,4 +37,9 @@ like in example below.
3737
3838
### your code
3939
40-
allure_report("path/to/result/dir")
40+
allure_report("path/to/result/dir")
41+
42+
Usage examples
43+
--------------
44+
45+
See usage examples `here <examples>`_.

allure-behave/examples/attachment.rst

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
===========
2+
Attachments
3+
===========
4+
5+
You can attach data and files to behave test results. An attachment can be added
6+
from a step definition function or from a hook. See examples below for more
7+
details.
8+
9+
----------------------------------
10+
Attach data from a step definition
11+
----------------------------------
12+
13+
The easiest way to add an attachment is to call the :code:`allure.attach`
14+
function from a step definition:
15+
16+
Feature file:
17+
^^^^^^^^^^^^^
18+
.. code:: gherkin
19+
:name: data-attachment-feature
20+
21+
Feature: Allure attachments in behave tests
22+
Scenario: Data attachment from step definitions
23+
Given a step that adds a named attachment
24+
And a step that adds a typed named attachment
25+
26+
Step definition file:
27+
^^^^^^^^^^^^^^^^^^^^^
28+
.. code:: python
29+
:name: data-attachment-steps
30+
31+
import allure
32+
from behave import given
33+
34+
@given("a step that adds a named attachment")
35+
def step_impl(context):
36+
allure.attach(
37+
"This is the attachment with the name 'step.txt'",
38+
name="step.txt"
39+
)
40+
41+
@given("a step that adds a typed named attachment")
42+
def step_impl(context):
43+
allure.attach(
44+
(
45+
"[DEBUG] This attachment is named 'trace.log' and has TEXT "
46+
"document appearance"
47+
),
48+
name="trace.log",
49+
attachment_type=allure.attachment_type.TEXT
50+
)
51+
52+
----------------------------------
53+
Attach file from a step definition
54+
----------------------------------
55+
56+
Call the :code:`allure.attach.file` function to attach a file:
57+
58+
Feature file:
59+
^^^^^^^^^^^^^
60+
.. code:: gherkin
61+
:name: file-attachment-feature
62+
63+
Feature: Allure attachments in behave tests
64+
Scenario: File attachment from a step definition
65+
Given a step that attaches a file
66+
67+
Step definition file:
68+
^^^^^^^^^^^^^^^^^^^^^
69+
.. code:: python
70+
:name: file-attachment-steps
71+
72+
import allure
73+
from behave import given
74+
75+
@given("a step that attaches a file")
76+
def step_impl(context):
77+
allure.attach.file(
78+
"./logs/web",
79+
name="web.log",
80+
attachment_type=allure.attachment_type.TEXT
81+
)
82+
83+
------------------
84+
Attach from a hook
85+
------------------
86+
87+
You can also attach data and files from a behave hook, e.g., from the
88+
:code:`after_scenario`:
89+
90+
.. code:: python
91+
:name: attach-hook
92+
93+
import allure
94+
95+
def after_scenario(context, scenario):
96+
allure.attach(
97+
"This attachment will appear on a scenario level",
98+
name="attachment.txt",
99+
attachment_type=allure.attachment_type.TEXT
100+
)
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
=====================================
2+
Provide a description for a test case
3+
=====================================
4+
5+
Scenario description can be added in various ways:
6+
7+
#. In a .feature file
8+
#. Dynamically in a step definition
9+
#. Dynamically in a hook (e.g., before_scenario or after_scenario)
10+
11+
-----------------------------
12+
Description in a feature file
13+
-----------------------------
14+
15+
The easiest way to add a description to a test is to specify it directly in the
16+
corresponding scenario in the .feature file. For example:
17+
18+
.. code-block:: gherkin
19+
:name: description-in-feature-feature
20+
21+
Feature: Allure description for behave tests
22+
Scenario: Description from a .feature file
23+
This scenario has a description.
24+
This description spans across multiple lines.
25+
26+
Given noop
27+
28+
The step definition is trivial:
29+
30+
.. code-block:: python
31+
:name: description-in-feature-steps
32+
33+
from behave import given
34+
35+
@given("noop")
36+
def step_impl(context):
37+
pass
38+
39+
-------------------
40+
Dynamic description
41+
-------------------
42+
43+
A description can be specified dynamically with the
44+
:code:`allure.dynamic.description` function. This is useful if you want to
45+
include runtime values in the description.
46+
47+
48+
Description in a step definition
49+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
Let's suppose, we want to add a description to the following test:
52+
53+
.. code-block:: gherkin
54+
:name: description-in-step-feature
55+
56+
Feature: Allure description for behave tests
57+
Scenario: Description from a step definition
58+
Given description is provided in a step definition
59+
60+
We can achieve that using the following step definition:
61+
62+
.. code-block:: python
63+
:name: description-in-step-steps
64+
65+
from behave import given
66+
import allure
67+
68+
@given("description is provided in a step definition")
69+
def step_impl(context):
70+
allure.dynamic.description(
71+
"This scenario has a description specified by the step definition"
72+
)
73+
74+
75+
Description in a hook
76+
^^^^^^^^^^^^^^^^^^^^^
77+
78+
It's also possible to add a description from a hook in the
79+
:code:`environment.py` file.
80+
81+
Suppose we have the following feature file (and step definition is the same as
82+
in `Description in a feature file`_):
83+
84+
.. code-block:: gherkin
85+
:name: description-in-hook-feature
86+
87+
Feature: Allure description for behave tests
88+
Scenario: Description from the before_scenario hook
89+
Given noop
90+
91+
Scenario: Description from the after_scenario hook
92+
Given noop
93+
94+
We can provide a description in the :code:`environment.py` like this:
95+
96+
.. code-block:: python
97+
:name: description-in-hook-env
98+
99+
import allure
100+
101+
def before_scenario(context, scenario):
102+
if "before_scenario" in scenario.name:
103+
allure.dynamic.description(
104+
"This scenario has a description specified in the "
105+
"before_scenario hook"
106+
)
107+
108+
109+
def after_scenario(context, scenario):
110+
if "after_scenario" in scenario.name:
111+
allure.dynamic.description(
112+
"This scenario has a description specified in the "
113+
"after_scenario hook"
114+
)

0 commit comments

Comments
 (0)