How to programatically ignore a unit test?

I have a unit test that can't reliably run on some systems, because an API it uses might be not supported.
I can detect that at runtime (but not statically) and would like to "abort" such test in such a way that it is shown as ignored. Is it possible?

You could make the test succeed at runtime simply by not performing the meat of the test. Is there a reason you specifically want it to report that the test was ignored?

(I suppose because the difference between "success" and "ignored" is meaningful to a human reviewing the results?)

There's some related discussion in this IRLO thread:

It sounds like there isn't a great solution at present.

1 Like

This is what I did, but I'm not fully satisfied with this, as this could trick someone into believing a feature was tested and is fine, when in fact it wasn't tested at all. And even worse: it actually does not work properly on the system where the test has been executed. So it might confuse the user who has built my software from scratch and has run the tests.

Another choice is just failing the test, but then it generates needless bug reports, which are not really bugs, because the feature cannot be supported on some configurations.

One use case I can think of is being able to skip slow/expensive tests unless you are in a CI or staging environment.

When developing I use cargo watch to automatically typecheck my code and run tests. I've got some integration tests which compile temporary Rust crates and being able to ignore those tests unless a condition is satisfied (e.g. environment variable is set).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.