allure-framework / allure-framework/allure-python

Attribute error in @allure.title when using @pytest.fixture(params=[...]

Đang mở
#873 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
theme:pytest
Ngôn ngữ chính
Python
Star
814
Fork
260
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

@allure.title decorator doesn't correctly formats a title string when using a parametrized fixture and having that fixture skip a test or raise an error:

```
import pytest
import allure

class TestClass:
@pytest.fixture(params=[1, 2]) # <-- causes AttributeError: 'int' object has no attribute 'one'
# @pytest.fixture()
def params(self):
# will cause AttributeError in allure.title
# if this fixture is skipping tests
pytest.skip('skip')

# or raising an error
raise ValueError('aa')

class _Params:
"""some params every test needs"""
one = 1
two = 2

# but no error if it returns a value
return _Params()

@allure.title('should display "1" {params.one}')
def test_func(self, params): # <-- causes AttributeError: 'int' object has no attribute 'one'
assert params.one == 1
```
```
self = , field_name = 'params.one', args = (), kwargs = {'param_id': '2', 'params': 2}

def get_field(self, field_name, args, kwargs):
first, rest = _string.formatter_field_name_split(field_name)

obj = self.get_value(first, args, kwargs)

# loop through the rest of the field_name, doing
# getattr or getitem as needed
for is_attr, i in rest:
if is_attr:
> obj = getattr(obj, i)
^^^^^^^^^^^^^^^
E AttributeError: 'int' object has no attribute 'one'

/usr/lib64/python3.12/string.py:305: AttributeError
=================================================================== short test summary info ====================================================================
ERROR p.py::TestClass::test_func[1] - AttributeError: 'int' object has no attribute 'one'
ERROR p.py::TestClass::test_func[2] - AttributeError: 'int' object has no attribute 'one'
====================================================================== 2 errors in 0.14s =======================================================================
```

This is shadowing the real error or skip in the fixture and is similar to #670

```
allure-pytest==2.15.0
pytest==8.4.1
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu từ đường dẫn định dạng của @allure.title và allure_commons.utils.SafeFormatter.get_field được hiển thị trong traceback; so sánh với hành vi được mô tả trong #670. Tái hiện các trường hợp skip và lỗi của fixture được tham số hóa, sau đó xác minh rằng skip ban đầu của pytest hoặc ValueError được báo cáo thay vì AttributeError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.