Comments (6)
You can use the current thread name instead.... see https://github.com/la10736/rstest/blob/master/rstest_test/src/utils.rs#L349
I've planned to write a fixture for it but I never did it 😢
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
from rstest.
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)
}
from rstest.
I mean that if you run cargo test -- --nocapture
on the follow code
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
mdamico@miklap:~/dev_random/t_117$ cargo test -- --nocapture
Compiling t_117 v0.1.0 (/home/mdamico/dev_random/t_117)
Finished test [unoptimized + debuginfo] target(s) in 0.19s
Running unittests src/lib.rs (target/debug/deps/t_117-755bac183b006419)
running 2 tests
[src/lib.rs:14] testname = "my_test::case_1"
[src/lib.rs:14] testname = "my_test::case_2"
thread 'my_test::case_2' panicked at 'assertion failed: dbg!(testname).contains(v)', src/lib.rs:14:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test my_test::case_1 ... ok
test my_test::case_2 - should panic ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Doc-tests t_117
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
As you can see testname
fixture is exactly the name of the test.
from rstest.
I forgot to mention that is not so hard to get description from the test name.
I understand that you would like to have the description available in the test. It could be a possibility to introduce something like
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 😢
from rstest.
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!
from rstest.
I don't want to lose the context idea.
from rstest.
Related Issues (20)
- Please clearly state the MSRV in the README and documentation and use the "rust-version" flag. HOT 2
- Add capability to ignore arguments HOT 3
- [vscode] text wrapping for run/debug test buttons
- Misleading error messaging when defining a test that includes a lifetime argument HOT 1
- Support argument destructuring for `#[values(...)]` HOT 1
- Injecting static types HOT 5
- Create a fixture from `files` attribute HOT 3
- skip cases based on feature flag? HOT 5
- `#[once]` fixtures are unsound for types that are not `Sync` HOT 4
- clippy::duplicated_attributes warning with rust 1.79.0-nightly HOT 3
- By-reference fixtures HOT 12
- Update `rstest_reuse` docs and release new version
- `#[from(source)]` should accept path also and not just idents
- rstest_reuse: "the `async` keyword is missing from the function declaration" HOT 1
- replace return <expr>; with <expr> [needless_return] HOT 3
- Support dynamic `#[values]` HOT 1
- Feature: Optional label in the `#[case...]` HOT 1
- Dynamically set #[values(..)] HOT 1
- New test files are only recognized after `cargo clean` HOT 4
- feat: provide a cargo feature to disable the proc macro inference in #221 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rstest.