pytest-dev / pytest-timeout

MIT License
216 stars 64 forks source link

Customize pytest error message #179

Open pedro-psb opened 1 month ago

pedro-psb commented 1 month ago

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.

flub commented 1 month ago

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.

pedro-psb commented 1 month ago

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.

RonnyPfannschmidt commented 1 month ago

The proposed message is much better

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

This is for beginners friendlyness

nicoddemus commented 1 month ago

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.

pedro-psb commented 1 month ago

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.

nicoddemus commented 1 month ago

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,

flub commented 1 month ago

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: