-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Get test case name #177
Comments
You can use the current thread name instead.... see https://github.com/la10736/rstest/blob/master/rstest_test/src/utils.rs#L349 Anyway you can write a fixture #[fixture]
pub fn testname() -> String {
thread::current().name().unwrap().to_string()
} and use it in your own test: #[rstest]
#[case("my_test")]
fn my_test(testname: String, v: &str) {
assert!(testname.contains(v);
} I didn't try it but should work |
Hmm not sure I’m understanding. What I meant is something like: #[rstest]
#[case::case1("case1")]
#[case::case2("case2")]
fn my_test(case_name: &str, v: &str) {
assert_eq!(case_name, v)
} |
I mean that if you run use rstest::*;
use std::thread;
#[fixture]
pub fn testname() -> String {
thread::current().name().unwrap().to_string()
}
#[rstest]
#[case("my_test")]
#[should_panic]
#[case("something_else")]
fn my_test(testname: String, #[case] v: &str) {
assert!(dbg!(testname).contains(v));
} You'll see the follow output
As you can see |
I forgot to mention that is not so hard to get description from the test name. use rstest::{rstest, Ctx};
#[rstest]
#[case::case1("case1")]
#[case::case2("case2")]
fn my_test(#[context] ctx: Ctx, v: &str) {
assert_eq!(ctx.description().unwrap(), v)
} It could be useful and clean. I hope to have some time to implement it.... but is quite hard 😢 |
Here’s what I ended up with: https://github.com/adriangb/pgpq/blob/b0b0f8c77c862c0483d81571e76f3a2b746136fc/pgpq/src/lib.rs#L649-L669 thanks for the help and crate! |
I don't want to lose the context idea. |
I've stared to implement test context. What's missed
|
When using
case::some_description
would it be possible to also get that value as a parameter to the test function? My use case is writing a file / snapshot test with my data so I'd like to re-use that identifier for the filename.The text was updated successfully, but these errors were encountered: