Skip to content

Commit

Permalink
Refactor tests to use pytest as a test runner for all the packages (#732
Browse files Browse the repository at this point in the history
)
  • Loading branch information
delatrie authored Mar 1, 2023
1 parent 919d3df commit 86cff25
Show file tree
Hide file tree
Showing 376 changed files with 10,315 additions and 6,542 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
max-line-length = 120
import-order-style = google
inline-quotes = "
exclude =
./tests/allure_behave/acceptance/**/test-data/**
./tests/allure_behave/acceptance/behave_support/background/background_steps.py
per-file-ignores =
./allure-python-commons/src/model2.py:A003
34 changes: 16 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@ jobs:
- allure-behave/**
- allure-python-commons/**
- allure-python-commons-test/**
- tests/*.py
- tests/allure_behave/**
allure-nose2:
- allure-nose2/**
- allure-python-commons/**
- allure-python-commons-test/**
- tests/*.py
- tests/allure_nose2/**
allure-pytest:
- allure-pytest/**
- allure-python-commons/**
- allure-python-commons-test/**
- tests/*.py
- tests/allure_pytest/**
allure-pytest-bdd:
- allure-pytest-bdd/**
- allure-python-commons/**
- allure-python-commons-test/**
- tests/*.py
- tests/allure_pytest_bdd/**
allure-robotframework:
- allure-robotframework/**
- allure-python-commons/**
- allure-python-commons-test/**
- tests/*.py
- tests/allure_robotframework/**
allure-python-commons: allure-python-commons/**
allure-python-commons-test: allure-python-commons-test/**
Expand Down Expand Up @@ -63,9 +73,6 @@ jobs:
runs-on: ubuntu-latest
needs: [commons, changes]
if: ${{ needs.changes.outputs.packages != '[]' }}
strategy:
matrix:
package: ${{ fromJSON(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v3

Expand All @@ -74,24 +81,14 @@ jobs:
with:
python-version: "3.11"

- name: Get commons from cache
id: commons
uses: actions/cache@v3
with:
path: dist/
key: commons-${{ github.sha }}

- name: Install packages
run: pip install dist/allure-python-commons*.tar.gz &&
pip install ./${{ matrix.package }} &&
pip install -r ${{ matrix.package }}/requirements.txt
- name: Install linting packages
run: pip install -r ./requirements/linting.txt

- name: Static check ${{ matrix.package }}
working-directory: ${{ matrix.package }}
- name: Linting the codebase
run: poe linter

build:
name: Build package
name: Test package
runs-on: ubuntu-latest
needs: [linters, commons, changes]
if: ${{ needs.changes.outputs.packages != '[]' }}
Expand Down Expand Up @@ -120,7 +117,8 @@ jobs:
- name: Install packages
run: pip install dist/allure-python-commons*.tar.gz &&
pip install ./${{ matrix.package }} &&
pip install -r ${{ matrix.package }}/requirements.txt
pip install -r ./requirements/testing.txt &&
pip install -r ./requirements/testing/${{ matrix.package }}.txt

- name: Test ${{ matrix.package }}
working-directory: ${{ matrix.package }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
*.egg-info

*/build
*/dist
*/dist

/.allure-report
/.allure-results
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The repository contains adaptors for Python-based test frameworks.
Documentation is available
[online](https://docs.qameta.io/allure-report/), also you can get help at
[gitter channel](https://gitter.im/allure-framework/allure-core)
[gitter channel](https://gitter.im/allure-framework/allure-core).

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

Allure [pytest](http://pytest.org) integration. It's developed as pytest
plugin and distributed via
[pypi](https://pypi.python.org/pypi/allure-pytest)
[pypi](https://pypi.python.org/pypi/allure-pytest).

[Usage examples](/allure-pytest/examples).

## Behave
[![Release
Expand All @@ -23,7 +25,9 @@ Status](https://img.shields.io/pypi/v/allure-behave)](https://pypi.python.org/py
Allure [behave](https://behave.readthedocs.io/en/latest/) integration.
Just external formatter that produce test results in allure2 format.
This package is available on
[pypi](https://pypi.python.org/pypi/allure-behave)
[pypi](https://pypi.python.org/pypi/allure-behave).

[Usage examples](/allure-behave/examples).

## Robot Framework
[![Release
Expand All @@ -33,9 +37,11 @@ Status](https://img.shields.io/pypi/v/allure-robotframework)](https://pypi.pytho
Allure [RobotFramework](http://robotframework.org/) integration. This
integration is a
[Listener](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-interface\))
and does not require changing autotests
and does not require changing autotests.

[Read more ...](/allure-robotframework/README.rst).

[Read more ...](/allure-robotframework/README.rst)
[Usage examples](/allure-robotframework/examples).

## Pytest-BDD

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

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

## Nose2
[![Release
Expand Down
11 changes: 8 additions & 3 deletions allure-behave/README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Allure Behave Formatter
=======================
.. image:: https://pypip.in/v/allure-behave/badge.png
.. image:: https://img.shields.io/pypi/v/allure-behave
:alt: Release Status
:target: https://pypi.python.org/pypi/allure-behave
.. image:: https://pypip.in/d/allure-behave/badge.png
.. image:: https://img.shields.io/pypi/dm/allure-behave
:alt: Downloads
:target: https://pypi.python.org/pypi/allure-behave

Expand Down Expand Up @@ -37,4 +37,9 @@ like in example below.
### your code
allure_report("path/to/result/dir")
allure_report("path/to/result/dir")
Usage examples
--------------

See usage examples `here <examples>`_.
100 changes: 100 additions & 0 deletions allure-behave/examples/attachment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
===========
Attachments
===========

You can attach data and files to behave test results. An attachment can be added
from a step definition function or from a hook. See examples below for more
details.

----------------------------------
Attach data from a step definition
----------------------------------

The easiest way to add an attachment is to call the :code:`allure.attach`
function from a step definition:

Feature file:
^^^^^^^^^^^^^
.. code:: gherkin
:name: data-attachment-feature
Feature: Allure attachments in behave tests
Scenario: Data attachment from step definitions
Given a step that adds a named attachment
And a step that adds a typed named attachment
Step definition file:
^^^^^^^^^^^^^^^^^^^^^
.. code:: python
:name: data-attachment-steps
import allure
from behave import given
@given("a step that adds a named attachment")
def step_impl(context):
allure.attach(
"This is the attachment with the name 'step.txt'",
name="step.txt"
)
@given("a step that adds a typed named attachment")
def step_impl(context):
allure.attach(
(
"[DEBUG] This attachment is named 'trace.log' and has TEXT "
"document appearance"
),
name="trace.log",
attachment_type=allure.attachment_type.TEXT
)
----------------------------------
Attach file from a step definition
----------------------------------

Call the :code:`allure.attach.file` function to attach a file:

Feature file:
^^^^^^^^^^^^^
.. code:: gherkin
:name: file-attachment-feature
Feature: Allure attachments in behave tests
Scenario: File attachment from a step definition
Given a step that attaches a file
Step definition file:
^^^^^^^^^^^^^^^^^^^^^
.. code:: python
:name: file-attachment-steps
import allure
from behave import given
@given("a step that attaches a file")
def step_impl(context):
allure.attach.file(
"./logs/web",
name="web.log",
attachment_type=allure.attachment_type.TEXT
)
------------------
Attach from a hook
------------------

You can also attach data and files from a behave hook, e.g., from the
:code:`after_scenario`:

.. code:: python
:name: attach-hook
import allure
def after_scenario(context, scenario):
allure.attach(
"This attachment will appear on a scenario level",
name="attachment.txt",
attachment_type=allure.attachment_type.TEXT
)
114 changes: 114 additions & 0 deletions allure-behave/examples/description.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
=====================================
Provide a description for a test case
=====================================

Scenario description can be added in various ways:

#. In a .feature file
#. Dynamically in a step definition
#. Dynamically in a hook (e.g., before_scenario or after_scenario)

-----------------------------
Description in a feature file
-----------------------------

The easiest way to add a description to a test is to specify it directly in the
corresponding scenario in the .feature file. For example:

.. code-block:: gherkin
:name: description-in-feature-feature
Feature: Allure description for behave tests
Scenario: Description from a .feature file
This scenario has a description.
This description spans across multiple lines.
Given noop
The step definition is trivial:

.. code-block:: python
:name: description-in-feature-steps
from behave import given
@given("noop")
def step_impl(context):
pass
-------------------
Dynamic description
-------------------

A description can be specified dynamically with the
:code:`allure.dynamic.description` function. This is useful if you want to
include runtime values in the description.


Description in a step definition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Let's suppose, we want to add a description to the following test:

.. code-block:: gherkin
:name: description-in-step-feature
Feature: Allure description for behave tests
Scenario: Description from a step definition
Given description is provided in a step definition
We can achieve that using the following step definition:

.. code-block:: python
:name: description-in-step-steps
from behave import given
import allure
@given("description is provided in a step definition")
def step_impl(context):
allure.dynamic.description(
"This scenario has a description specified by the step definition"
)
Description in a hook
^^^^^^^^^^^^^^^^^^^^^

It's also possible to add a description from a hook in the
:code:`environment.py` file.

Suppose we have the following feature file (and step definition is the same as
in `Description in a feature file`_):

.. code-block:: gherkin
:name: description-in-hook-feature
Feature: Allure description for behave tests
Scenario: Description from the before_scenario hook
Given noop
Scenario: Description from the after_scenario hook
Given noop
We can provide a description in the :code:`environment.py` like this:

.. code-block:: python
:name: description-in-hook-env
import allure
def before_scenario(context, scenario):
if "before_scenario" in scenario.name:
allure.dynamic.description(
"This scenario has a description specified in the "
"before_scenario hook"
)
def after_scenario(context, scenario):
if "after_scenario" in scenario.name:
allure.dynamic.description(
"This scenario has a description specified in the "
"after_scenario hook"
)
Loading

0 comments on commit 86cff25

Please sign in to comment.