Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allure2 for pytest should using get_closest_marker to replace the get_marker #307

Closed
1 of 3 tasks
tsbxmw opened this issue Nov 13, 2018 · 1 comment
Closed
1 of 3 tasks

Comments

@tsbxmw
Copy link
Contributor

tsbxmw commented Nov 13, 2018

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

D:\workspace\mine\python\haf\testcases>python -m pytest two.py --alluredir=./
============================= test session starts =============================
platform win32 -- Python 3.6.6, pytest-3.10.1, py-1.5.4, pluggy-0.7.1
rootdir: D:\workspace\mine\python\haf, inifile:
plugins: metadata-1.7.0, html-1.19.0, allure-pytest-2.5.3
collected 1 item

two.py .                                                                 [100%]

============================== warnings summary ===============================
testcases/two.py::Test_Allure::()::test_allure_pytest
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:24: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    return marker.args[0] if marker and marker.args else None
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:24: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    return marker.args[0] if marker and marker.args else None
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:48: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    label_type = marker.kwargs['label_type']
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:52: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    for value in marker.args:

-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================== 1 passed, 4 warnings in 0.06 seconds =====================

image

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

1, using pytest 3.1.0 ==> pip install pytest==3.1.0
2, using allure-pytest 2.5.3 ==> pip install allure-pytest==2.5.3
3, write an sample pytest case : using allure marker

import pytest, os, sys, allure
class Test_Allure:
        @allure.description("test for allure")
        @allure.story("test the allure in pytest case")
        def test_allure_pytest(self):
            print("test now")

4, python -m pytest two.py --alluredir=./

D:\workspace\mine\python\haf\testcases>python -m pytest two.py --alluredir=./
============================= test session starts =============================
platform win32 -- Python 3.6.6, pytest-3.10.1, py-1.5.4, pluggy-0.7.1
rootdir: D:\workspace\mine\python\haf, inifile:
plugins: metadata-1.7.0, html-1.19.0, allure-pytest-2.5.3
collected 1 item

two.py .                                                                 [100%]

============================== warnings summary ===============================
testcases/two.py::Test_Allure::()::test_allure_pytest
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:24: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    return marker.args[0] if marker and marker.args else None
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:24: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    return marker.args[0] if marker and marker.args else None
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:48: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    label_type = marker.kwargs['label_type']
  C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\allure_pytest\utils.py:52: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
  Please use node.get_closest_marker(name) or node.iter_markers(name).
  Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
    for value in marker.args:

-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================== 1 passed, 4 warnings in 0.06 seconds =====================

What is the expected behavior?

No warnings in the pytest when using the allure markers

What is the motivation / use case for changing the behavior?

https://docs.pytest.org/en/latest/mark.html#updating-code

using function of pytest get_closet_marker' to replace the get_marker'

image

in utils.py,

in function allure_labels and allure_links, using get_closet_marker' to replace the get_marker'
in function get_marker_value , using get_closest_marker to replace keywords.get

# in utils.py
def get_marker_value(item, keyword):
    #marker = item.keywords.get(keyword)
    marker = item.get_closest_marker(keyword)
    return marker.args[0] if marker and marker.args else None


def allure_labels(item):
    for keyword in item.keywords.keys():
        if keyword.startswith(ALLURE_LABEL_PREFIX):
            #marker = item.get_marker(keyword)
            marker = item.get_closest_marker(keyword)
            label_type = marker.kwargs['label_type']
            if label_type in ALLURE_UNIQUE_LABELS:
                yield (label_type, marker.args[0])
            else:
                for value in marker.args:
                    yield (label_type, value)


def allure_links(item):
    for keyword in item.keywords.keys():
        if keyword.startswith(ALLURE_LINK_PREFIX):
            #marker = item.get_marker(keyword)
            marker = item.get_closest_marker(keyword)
            link_type = marker.kwargs['link_type']
            url = marker.args[0]
            name = marker.kwargs['name']
            yield (link_type, url, name)

Please tell us about your environment:

Allure version 2.5.3
Test framework pytest@3.10.1
Allure adaptor allure-pytest@2.5.3
Generate report using allure-pytest@2.5.3

Other information

@baev baev transferred this issue from allure-framework/allure2 Nov 13, 2018
@sseliverstov
Copy link
Contributor

fixed in #306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants