helper.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pytest
  2. import allure_commons
  3. from allure_pytest.utils import ALLURE_DESCRIPTION_MARK, ALLURE_DESCRIPTION_HTML_MARK
  4. from allure_pytest.utils import ALLURE_LABEL_MARK, ALLURE_LINK_MARK
  5. from allure_pytest.utils import format_allure_link
  6. class AllureTitleHelper:
  7. @allure_commons.hookimpl
  8. def decorate_as_title(self, test_title):
  9. def decorator(func):
  10. # pytest.fixture wraps function, so we need to get it directly
  11. if getattr(func, '__pytest_wrapped__', None):
  12. function = func.__pytest_wrapped__.obj
  13. else:
  14. function = func
  15. function.__allure_display_name__ = test_title
  16. return func
  17. return decorator
  18. class AllureTestHelper:
  19. def __init__(self, config):
  20. self.config = config
  21. @allure_commons.hookimpl
  22. def decorate_as_description(self, test_description):
  23. allure_description = getattr(pytest.mark, ALLURE_DESCRIPTION_MARK)
  24. return allure_description(test_description)
  25. @allure_commons.hookimpl
  26. def decorate_as_description_html(self, test_description_html):
  27. allure_description_html = getattr(pytest.mark, ALLURE_DESCRIPTION_HTML_MARK)
  28. return allure_description_html(test_description_html)
  29. @allure_commons.hookimpl
  30. def decorate_as_label(self, label_type, labels):
  31. allure_label = getattr(pytest.mark, ALLURE_LABEL_MARK)
  32. return allure_label(*labels, label_type=label_type)
  33. @allure_commons.hookimpl
  34. def decorate_as_link(self, url, link_type, name):
  35. url = format_allure_link(self.config, url, link_type)
  36. allure_link = getattr(pytest.mark, ALLURE_LINK_MARK)
  37. name = url if name is None else name
  38. return allure_link(url, name=name, link_type=link_type)