r-lib / testthat

An R 📦 to make testing 😀
https://testthat.r-lib.org
Other
888 stars 318 forks source link

Option in `expect()` for turning off backtrace #1888

Open yangsophieee opened 11 months ago

yangsophieee commented 11 months ago

Hi, I saw that a backtrace was added for wrapped expectations (#1307), which is a great addition for debugging. However, I was wondering if it would be useful to add an option for turning the backtrace off. I've tried fiddling with the current trace and trace_env arguments but looking at the code it doesn't seem I'd be able to use them to turn it off.

The reason I'd like to turn them off is I'm using testthat expectations and CompactProgressReporter to summarise problems with data and metadata that is input to a database built by our package. I've created my own expectations which wrap other expectations in order to fully customise the failure messages. I've written them to be accessible to users and so I'd like to turn off the backtrace, since it clutters the progress reporter and would be meaningless to anyone unfamiliar with the package's inner workings.

Thanks very much for the amazing package!

hadley commented 11 months ago

Can you give a few more details? I don't think you'd want to turn off capturing the traces, but we could provide more options to prevent their display (and possibly make that the default in the compact reporter?)

yangsophieee commented 11 months ago

Yes that's exactly right, sorry for not being specific! I would like to prevent their display, not turn off capturing the traces. I don't mind whether that's the default in the compact reporter, but I guess it would make sense.

Here's an example of a failure from the reporter where I made a custom message and would like to stop the backtrace from being displayed:

image