allure-framework / allure-framework/allure-python

Provide a custom repr for function params in `@step` decorator

未关闭
#642 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
theme:pytest
主要语言
Python
星标
814
派生
260
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

打开贡献指南

调研方向

从 allure-python-commons/src/utils.py 中的特殊情况表示逻辑开始,追踪 @step 如何收集函数参数。定义如何接受并将显式 formatter 应用于参数,然后验证 numpy 数组和字典能够生成所请求的紧凑输出,同时不改变默认行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
numpy, python
领域
testing-qa
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。