Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find the test name for unit tests, in release mode, with test-threads=1 #105

Closed
zazabe opened this issue Mar 17, 2020 · 3 comments

Comments

@zazabe
Copy link
Contributor

zazabe commented Mar 17, 2020

insta is not able to find the test name for unit tests, in release mode, with --test-threads=1 option, even with the "backtrace" feature.

main.rs

#[test]
fn test_snapshot() {
    insta::assert_snapshot!("foo", @"foo");
}

Cargo.toml

[...]
[dependencies]
insta = { version = "0.15.0", features = ["backtrace"] }

test result:

$ cargo test --release --quiet -- --test-threads=1

running 1 test
F
failures:

---- test_snapshot stdout ----
thread 'main' panicked at 'Cannot determine test name from backtrace, no snapshot name can be generated.', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/insta-0.15.0/src/runtime.rs:503:5
[...]
@zazabe
Copy link
Contributor Author

zazabe commented Mar 17, 2020

I opened this ticket for the record, feel free to close.

Workaround

A workaround is to override the debug setting of the bench profile, used by cargo test --release:

Cargo.toml

[...]
[dependencies]
insta = { version = "0.15.0", features = ["backtrace"] }

[profile.bench]
debug = 1 # line tables only

test result:

$ cargo test --release --quiet -- --test-threads=1

running 1 test
.
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

@mitsuhiko
Copy link
Owner

Unfortunately there is nothing I can do about this with the tools available currently. It might be worth filing a feature request for rust-test.

@mitsuhiko
Copy link
Owner

I filed an issue here: rust-lang/rust#70492

mitsuhiko added a commit that referenced this issue Jan 25, 2022
We used to detect the snapshot names form the current thread.  This has
been very unrealiable in a lot of cases.  This changes the behavior so
that the function name is used instead by using `std::any::type_name`.

This does change behavior slightly but most users should not notice this
change except if they relied on helper functions.  In that case using a
macro is a better solution most likely.

Refs #127 and #105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants