test-context icon indicating copy to clipboard operation
test-context copied to clipboard

Allow setup and teardown to return Result<()>

Open phiresky opened this issue 1 year ago • 1 comments

#[test] functions in rust can return a Result<()> to indicate a test failed. this is very convenient so you can use the ? operator.

When converting test functions to use test-context, this means if the setup function has ? statements, they have to be removed, or you have to wrap all the functions. For example, in lemmy we had to add this:

image

It would be very convenient if there was a way to return Result<(), anything> in async test context, so you don't have to use unwrap and a wrapper (which the linter does not like)

phiresky avatar Dec 02 '24 12:12 phiresky

Hi @phiresky ! Sorry for the late reply, I just got to see it right now.

I will take a look into it and write back :)

Also if you want to contribute feel completely free to do so, I am very busy at the moment at work and moving to a different country so it might take a while for me to focus on this issue.

Thanks for reaching out, have a good end of the year :))

JasterV avatar Dec 11 '24 17:12 JasterV

I'd close this as I don't find it necessary to return a result on tests, it should be fine to use "expect" or "unwrap" when testing

JasterV avatar Oct 07 '25 09:10 JasterV