Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a97bf8b
test(pytest-bdd): cover attachments with tests
delatrie Mar 13, 2025
3ab7744
feat(pytest-bdd): add description support
delatrie Mar 13, 2025
5d05035
feat(pytest-bdd): add description_html support
delatrie Mar 13, 2025
071bb39
feat(pytest-bdd): add title support
delatrie Mar 13, 2025
0b04c98
feat(pytest-bdd): add labels support
delatrie Mar 14, 2025
4748a3d
fix(pytest-bdd): unduplicate feature labels
delatrie Mar 14, 2025
b2777dd
feat(pytest-bdd): add tags support
delatrie Mar 14, 2025
4f92727
fix: classifier fixes
delatrie Mar 14, 2025
3bda8ca
test(pytest-bdd): cover specific labels with tests
delatrie Mar 14, 2025
aa562bc
feat(pytest-bdd): implement links
delatrie Mar 14, 2025
507be82
feat(pytest-bdd): implement --allure-link-pattern
delatrie Mar 14, 2025
f29fa77
feat(pytest-bdd): implement dynamic parameters
delatrie Mar 14, 2025
d147a48
feat(pytest-bdd): implement substeps (WIP)
delatrie Mar 14, 2025
1f996bf
feat(pytest-bdd): improve steps reporting
delatrie Mar 18, 2025
c69b5a9
refactor(pytest-bdd): merge utils
delatrie Mar 19, 2025
e139391
refactor(pytest-bdd): mode attach hooks to listener module
delatrie Mar 19, 2025
534d972
fix(pytest-bdd): better xfail and teardown support
delatrie Mar 19, 2025
3fd3cec
refactor(pytest-bdd): merge types module into storage
delatrie Mar 19, 2025
9a01087
refactor(pytest-bdd): linter
delatrie Mar 19, 2025
6ae4eb8
refactor(pytest-bdd): replace equal_to with strings
delatrie Mar 20, 2025
69f215a
feat(pytest-bdd): remove params from scenario names
delatrie Mar 20, 2025
7aac712
feat(pytest-bdd): allure.title for steps
delatrie Mar 21, 2025
64d83ea
feat(pytest-bdd): step arguments support
delatrie Mar 21, 2025
09b6ad2
test(pytest-bdd): cover module level markers
delatrie Mar 24, 2025
69da6e9
test(pytest-bdd): cover attach from hooks
delatrie Mar 24, 2025
1174859
test(pytest-bdd): cover docstr and datatables backward compat
delatrie Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions allure-behave/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
'Topic :: Software Development :: Testing :: BDD',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
]

setup_requires = [
Expand Down Expand Up @@ -66,4 +66,3 @@ def main():

if __name__ == '__main__':
main()

2 changes: 1 addition & 1 deletion allure-nose2/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
'Topic :: Software Development :: Testing',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
]

setup_requires = [
Expand Down
3 changes: 2 additions & 1 deletion allure-pytest-bdd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
'License :: OSI Approved :: Apache Software License',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Testing :: BDD',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
]

setup_requires = [
Expand Down
119 changes: 119 additions & 0 deletions allure-pytest-bdd/src/allure_api_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import pytest

import allure_commons

from allure_commons.model2 import Label
from allure_commons.model2 import Link
from allure_commons.model2 import Parameter
from allure_commons.utils import represent

from .utils import ALLURE_DESCRIPTION_HTML_MARK
from .utils import ALLURE_DESCRIPTION_MARK
from .utils import ALLURE_LABEL_MARK
from .utils import ALLURE_LINK_MARK
from .utils import ALLURE_TITLE_ATTR

from .utils import apply_link_pattern
from .utils import attach_data
from .utils import attach_file
from .utils import get_link_patterns
from .steps import start_step
from .steps import stop_step


class AllurePytestBddApiHooks:
def __init__(self, config, lifecycle):
self.lifecycle = lifecycle
self.__link_patterns = get_link_patterns(config)

@allure_commons.hookimpl
def decorate_as_title(self, test_title):

def decorator(fn):
setattr(fn, ALLURE_TITLE_ATTR, test_title)
return fn

return decorator

@allure_commons.hookimpl
def add_title(self, test_title):
with self.lifecycle.update_test_case() as test_result:
test_result.name = test_title

@allure_commons.hookimpl
def decorate_as_description(self, test_description):
allure_description_mark = getattr(pytest.mark, ALLURE_DESCRIPTION_MARK)
return allure_description_mark(test_description)

@allure_commons.hookimpl
def add_description(self, test_description):
with self.lifecycle.update_test_case() as test_result:
test_result.description = test_description

@allure_commons.hookimpl
def decorate_as_description_html(self, test_description_html):
allure_description_html_mark = getattr(pytest.mark, ALLURE_DESCRIPTION_HTML_MARK)
return allure_description_html_mark(test_description_html)

@allure_commons.hookimpl
def add_description_html(self, test_description_html):
with self.lifecycle.update_test_case() as test_result:
test_result.descriptionHtml = test_description_html

@allure_commons.hookimpl
def decorate_as_label(self, label_type, labels):
allure_label_mark = getattr(pytest.mark, ALLURE_LABEL_MARK)
return allure_label_mark(*labels, label_type=label_type)

@allure_commons.hookimpl
def add_label(self, label_type, labels):
with self.lifecycle.update_test_case() as test_result:
test_result.labels.extend(
Label(name=label_type, value=value) for value in labels or []
)

@allure_commons.hookimpl
def decorate_as_link(self, url, link_type, name):
url = apply_link_pattern(self.__link_patterns, link_type, url)
allure_link_mark = getattr(pytest.mark, ALLURE_LINK_MARK)
return allure_link_mark(url, name=name, link_type=link_type)

@allure_commons.hookimpl
def add_link(self, url, link_type, name):
url = apply_link_pattern(self.__link_patterns, link_type, url)
with self.lifecycle.update_test_case() as test_result:
test_result.links.append(Link(url=url, name=name, type=link_type))

@allure_commons.hookimpl
def add_parameter(self, name, value, excluded, mode):
with self.lifecycle.update_test_case() as test_result:
test_result.parameters.append(
Parameter(
name=name,
value=represent(value),
excluded=excluded,
mode=mode.value if mode else None,
),
)

@allure_commons.hookimpl
def start_step(self, uuid, title, params):
start_step(self.lifecycle, step_uuid=uuid, title=title, params=params)

@allure_commons.hookimpl
def stop_step(self, uuid, exc_type, exc_val, exc_tb):
stop_step(
self.lifecycle,
uuid,
exception=exc_val,
exception_type=exc_type,
traceback=exc_tb,
)

@allure_commons.hookimpl
def attach_data(self, body, name, attachment_type, extension):
attach_data(self.lifecycle, body, name, attachment_type, extension)

@allure_commons.hookimpl
def attach_file(self, source, name, attachment_type, extension):
attach_file(self.lifecycle, source, name, attachment_type, extension)
50 changes: 48 additions & 2 deletions allure-pytest-bdd/src/plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import allure_commons
import argparse
import os

import allure_commons
from allure_commons.logger import AllureFileLogger
from allure_commons.lifecycle import AllureLifecycle

from .allure_api_listener import AllurePytestBddApiHooks
from .pytest_bdd_listener import PytestBDDListener

from .utils import ALLURE_DESCRIPTION_MARK
from .utils import ALLURE_DESCRIPTION_HTML_MARK
from .utils import ALLURE_LABEL_MARK
from .utils import ALLURE_LINK_MARK


def pytest_addoption(parser):
parser.getgroup("reporting").addoption('--alluredir',
Expand All @@ -17,6 +27,27 @@ def pytest_addoption(parser):
dest="clean_alluredir",
help="Clean alluredir folder if it exists")

def link_pattern(string):
pattern = string.split(':', 1)
if not pattern[0]:
raise argparse.ArgumentTypeError("A link type is mandatory")

if len(pattern) != 2:
raise argparse.ArgumentTypeError("A link pattern is mandatory")
return pattern

parser.getgroup("general").addoption(
"--allure-link-pattern",
action="append",
dest="allure_link_pattern",
metavar="LINK_TYPE:LINK_PATTERN",
default=[],
type=link_pattern,
help="""A URL pattern for a link type. Allows short links in tests,
e.g., 'issue-1'. `pattern.format(short_url)` will be called to get
the full URL"""
)


def cleanup_factory(plugin):
def clean_up():
Expand All @@ -25,18 +56,33 @@ def clean_up():
return clean_up


def register_marks(config):
config.addinivalue_line("markers", f"{ALLURE_DESCRIPTION_MARK}: allure description")
config.addinivalue_line("markers", f"{ALLURE_DESCRIPTION_HTML_MARK}: allure description in HTML")
config.addinivalue_line("markers", f"{ALLURE_LABEL_MARK}: allure label marker")
config.addinivalue_line("markers", f"{ALLURE_LINK_MARK}: allure link marker")


def pytest_configure(config):
register_marks(config)

report_dir = config.option.allure_report_dir
clean = False if config.option.collectonly else config.option.clean_alluredir

if report_dir:
report_dir = os.path.abspath(report_dir)

pytest_bdd_listener = PytestBDDListener()
lifecycle = AllureLifecycle()

pytest_bdd_listener = PytestBDDListener(lifecycle)
config.pluginmanager.register(pytest_bdd_listener)
allure_commons.plugin_manager.register(pytest_bdd_listener)
config.add_cleanup(cleanup_factory(pytest_bdd_listener))

allure_api_impl = AllurePytestBddApiHooks(config, lifecycle)
allure_commons.plugin_manager.register(allure_api_impl)
config.add_cleanup(cleanup_factory(allure_api_impl))

file_logger = AllureFileLogger(report_dir, clean)
allure_commons.plugin_manager.register(file_logger)
config.add_cleanup(cleanup_factory(file_logger))
Loading