allure-framework / allure-framework/allure-python

The "excluded" and "mode" parameters of the allure.dynamic.parameter function are ignored for the pytest parameters

Đang mở
#822 0 bình luận 6 reaction 0 người được giao Xem trên GitHub
task:improvement 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ả

[//]: # (
. Note: for support questions, please use Stackoverflow or Gitter**.
. This repository's issues are reserved for feature requests and bug reports.
.
. In case of any problems with Allure Jenkins plugin** please use the following repository
. to create an issue: https://github.com/jenkinsci/allure-plugin/issues
.
. Make sure you have a clear name for your issue. The name should start with a capital
. letter and no dot is required in the end of the sentence. An example of good issue names:
.
. - The report is broken in IE11
. - Add an ability to disable default plugins
. - Support emoji in test descriptions
)

#### I'm submitting a ...
- [x] 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?

The "excluded" and "mode" parameters of the allure.dynamic.parameter function do not affect the display of the pytest parameter in the TestOps report.

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

My test looks something like this:

```python
@pytest.mark.parametrize('login, password', [('admin', 'secret')])
def test_authorization(login, password):
allure.dynamic.parameter('password', password, mode=allure.parameter_mode.MASKED)
...

```

In this case, the parameters of the test function are passed using pytest.mark.parametrize.

The output of the report file looks like this:

```json
{"name": "test_authorization[admin-secret]", "status": "passed", "parameters": [{"name": "login", "value": "'admin'"}, {"name": "password", "value": "'secret'"}], "start": 1718844940592, "stop": 1718844940592, "uuid": "1f59becc-6d3a-4be3-be5b-0ffbd257ec5b", "historyId": "36ae0f9494e1ff5a9b8153a55ab15428", "testCaseId": "2334cf5fc2f37123d71eab12c56f1a15", "fullName": "test_main#test_authorization", "labels": [{"name": "suite", "value": "test_main"}, {"name": "host", "value": "MYHOST"}, {"name": "thread", "value": "12440-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "test_main"}]}
```

#### What is the expected behavior?

The value of the "password" parameter is expected to be masked in the report.

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

---

#### Please tell us about your environment:

- Allure version: 2.10.0
- Test framework: pytest@8.2.2
- Allure adaptor: allure-pytest@2.13.5

#### Other information

The solution method:

Change the method of the AllureListener class to allure_pytest/listener.py

Current code:
```python
@allure_commons.hookimpl
def add_parameter(self, name, value, excluded, mode: ParameterMode):
test_result: TestResult = self.allure_logger.get_test(None)
existing_param = next(filter(lambda x: x.name == name, test_result.parameters), None)
if existing_param:
existing_param.value = represent(value)
else:
test_result.parameters.append(
Parameter(
name=name,
value=represent(value),
excluded=excluded or None,
mode=mode.value if mode else None
)
)
```

Proposal for a change:
```python
@allure_commons.hookimpl
def add_parameter(self, name, value, excluded, mode: ParameterMode):
test_result: TestResult = self.allure_logger.get_test(None)
existing_param = next(filter(lambda x: x.name == name, test_result.parameters), None)
if existing_param:
existing_param.value = represent(value)
existing_param.excluded = excluded or None
existing_param.mode = mode.value if mode else None
else:
test_result.parameters.append(
Parameter(
name=name,
value=represent(value),
excluded=excluded or None,
mode=mode.value if mode else None
)
)
```

With this implementation, the result file will look like this:

```json
{"name": "test_authorization[admin-secret]", "status": "passed", "parameters": [{"name": "login", "value": "'admin'"}, {"name": "password", "value": "'secret'", "mode": "masked"}], "start": 1718845042635, "stop": 1718845042635, "uuid": "88fa5ba0-faf1-40b0-a380-32c51a5f8907", "historyId": "36ae0f9494e1ff5a9b8153a55ab15428", "testCaseId": "2334cf5fc2f37123d71eab12c56f1a15", "fullName": "test_main#test_authorization", "labels": [{"name": "suite", "value": "test_main"}, {"name": "host", "value": "MYHOST"}, {"name": "thread", "value": "4536-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "test_main"}]}
```

[//]: # (
. e.g. detailed explanation, stacktraces, related issues, suggestions
. how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc
)

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

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

Hướng nghiên cứu

Bắt đầu trong allure_pytest/listener.py tại AllureListener.add_parameter và tái hiện vấn đề bằng một test pytest.mark.parametrize sử dụng allure.dynamic.parameter. So sánh JSON kết quả được tạo với metadata tham số mong đợi; hoàn tất khi các tham số pytest hiện có giữ nguyên mode được yêu cầu và các giá trị bị loại trừ.

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-qa
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả 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.