pytest-timeout icon indicating copy to clipboard operation
pytest-timeout copied to clipboard

Customize pytest error message

Open pedro-psb opened this issue 1 year ago • 7 comments

Hey, I want to request the addition of a setting to change the pytest error message. E.g:

# Current message
E       Failed: Timeout >300.0s

# What would be helpful in my context
E       [pytest-timeout] For some reason this test is hanging: Timeout >300.0s

I work on a project made of plugins where the CI is quite complex and often changes.

The pytest-timeout was introduced by the CI team and some test failed due to timeout on the plugin I was looking at. It took some time to figure out that this was a plugin that was introduced, and a more explicit message would have been helpful.

I can submit a PR if that's ok.

pedro-psb avatar Sep 11 '24 20:09 pedro-psb

pytest-timeout already announces itself in the reporting header like most other pytest plugins. I'm not sure I'm in favour of adding something like this, it adds maintenance complexity for very little in return. This feels more like a problem that should be solved in your CI pipeline or development communication.

flub avatar Sep 12 '24 08:09 flub

If maintenance complexity is a concern, what about just changing the error message to be more explicit? I don't disagree with any of what you said, but regardless, informative error messages are generally helpful. IMO, the information that this was raised by the plugin is meaningful, as timeouts may have multiple sources.

pedro-psb avatar Sep 12 '24 12:09 pedro-psb

The proposed message is much better

Let's use more obnoxious Exception type names+ expand the message text

This is for beginners friendlyness

RonnyPfannschmidt avatar Sep 12 '24 12:09 RonnyPfannschmidt

I believe @flub just misunderstood the request?

Basically just change the message from Failed: Timeout >300.0s to [pytest-timeout] For some reason this test is hanging: Timeout >300.0s (not customizable or anything).

Seems trivial and indeed better.

nicoddemus avatar Sep 12 '24 12:09 nicoddemus

I believe @flub just misunderstood the request?

He got it right, I proposed it to be customizable at first. That was an XY problem from my side. But yeah, the core request is to have a more informative error message title.

pedro-psb avatar Sep 12 '24 14:09 pedro-psb

On Thu, Sep 12, 2024, at 11:49 AM, Pedro Brochado wrote:

I believe @flub https://github.com/flub just misunderstood the request?

He got it right, I proposed it to be customizable at first. That was an XY problem from my side. But yeah, the core request is to have a better error message.

Ahh I'm so sorry, just skimmed the original message.

But I think the change as written before (without customization) would be trivial and a net win.

Cheers,

nicoddemus avatar Sep 12 '24 15:09 nicoddemus

Yeah, if people think the default message and exception types aren't clear enough that's probably more reasonable to change. Feel free to propose something, but I'll put some parameters around this:

  • It should be short, the section header should definitely render on an 80-columns wide terminal. Should probably aim to look good still in 60 columns.

  • It should be consistent with the rest of pytest's default UI.

flub avatar Sep 19 '24 18:09 flub