la10736 / rstest

Fixture-based test framework for Rust
Apache License 2.0
1.21k stars 43 forks source link

Add ability to use case name in parameter #279

Closed tbicr closed 1 month ago

tbicr commented 2 months ago

I wrote integration tests that run queries in database and I want to isolate this test's queries.

Case name looks good option for me to achieve isolation and visibility, now I duplicate case name in parameter:

#[rstest]
#[case::standard("standard", "")]
#[case::concurrent("concurrent", " CONCURRENTLY")]
fn test(#[case] case: &str, #[case] suffix: &str) {
   // CREATE TABLE test_{case} (...)
}

In general it works fine except situation when cases copy-pasted a lot and it require both places fix to avoid isolation issues.

Option when I can use case name as case parameter looks good improvement for my workflow:

#[rstest]
#[case::standard("")]
#[case::concurrent(" CONCURRENTLY")]
fn test(#[case_name] case: &str, #[case] suffix: &str) {
   // CREATE TABLE test_{case} (...)
}

I wonder if rstest has something similar or you can suggest how it can be implemented best way?

la10736 commented 2 months ago

You can use something like in #177 . Anyway I would find some time to implement the #[context] attribute.

tbicr commented 1 month ago

This works perfectly, thanks.