allure-framework / allure-framework/allure-python
Provide a custom repr for function params in `@step` decorator
- 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ả
I have a function like:
```
@step
def foo(x: np.ndarray, y: Dict[str, np.ndarray]): ...
```
It is marked with `@step` decorator and my problem is that the output in the allure repo is too large. I see that the special case of `represnet` is here https://github.com/allure-framework/allure-python/blob/3c74fd540021f776be7b52f8078c9d34eee5c3b6/allure-python-commons/src/utils.py#L167
So I was wondering how to handle other objects like `np.ndarray` or `Dict[str, np.ndarray]`?
One way is to subclass `dict` and give a nice `repr` to it, but what with a single numpy array?Sublassing it just so it got a better `repr` for allure looks... excessive?
Can `@step` accept an additional argument that will explicitly tell it hot to handle `obj -> str` representation?
#### I'm submitting a ...
- [x ] feature request
#### What is the current behavior?
A long text output in the allure report for types like `np.ndarray` or `Dict[str, np.ndarray]` that have long `repr`.
#### What is the expected behavior?
Make `@step` that receives explicit formatter so I can write:
```
def _my_repr(x: np.ndarray, y: Dict[str, np.ndarray]):
return format_1(x), format_2(t) # <-- custom formatting code here
@step(formatter=_my_repr)
def foo(x: np.ndarray, y: Dict[str, np.ndarray]): ...
```
#### Please tell us about your environment:
allure-pytest==2.9.45
allure-python-commons==2.9.45
pytest==6.2.5
#### Other information
I am willing on implementing that feature conditional on the fact there is a way of accepting that change to the mainstream. Will you accept a PR that parametrize `@step` in such a way?
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với logic biểu diễn các trường hợp đặc biệt trong allure-python-commons/src/utils.py và theo dõi cách @step thu thập các tham số của hàm. Xác định cách một formatter tường minh được tiếp nhận và áp dụng cho các tham số, sau đó xác minh rằng các mảng numpy và dictionary tạo ra đầu ra ngắn gọn được yêu cầu mà không thay đổi hành vi mặc định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- numpy, python
- Lĩnh vực
- testing-qa
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 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
- 38/100