Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Provide a custom repr for function params in @step decorator #642

Copy link
Copy link
Open
@Eugene-1984

Description

@Eugene-1984
Issue body actions

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

elif isinstance(item, (bytes, bytearray)):

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.