-
Notifications
You must be signed in to change notification settings - Fork 63
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
Warning: mocked function never used #410
Comments
What compiler version do you have, and how is your struct or trait defined? The warnings probably wouldn't be emitted if the trait were |
I use The struct is defined like that: #[async_trait]
#[automock]
pub(crate) trait Queries: Sync + Send {
async fn count_items(&self) -> Result<i64, anyhow::Error>;
// some more functions
// the ones which are actually not used in tests are having a warning
} Using |
So you're still seeing warnings for the expect_* methods? I think it would make sense for Mockall to suppress those. |
Yeah, exactly. After changing to Every |
Can confirm - |
You need to put |
How about an attr for methods that makes #[automock]
trait MyTrait {
fn foo(&self) -> u32;
#[nomock]
fn bar(&self, x: u32, y: u32) -> u32;
} This way, The only other way of suppressing those warnings is to use |
@rharish101 the problem should be fixed by using automock and async_trait in the correct order. Or are you still seeing this warning? |
Yes, I tried both positions. |
@rharish101 you aren't the OP, so I assume that your code is different. Would you please post it, along with your unwanted warnings? |
Here's a sample project with the following structure:
[package]
name = "dummy"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dev-dependencies]
mockall = "0.11.3"
mod foo;
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
use mockall::automock;
#[cfg_attr(test, automock)]
pub trait MyTrait<T> {
fn foo(&self, x: T);
} When simplifying my code into this dummy example, I noticed that the warnings are only raised (with
Note that Also, I didn't actually write a test that uses |
@rharish101 I can reproduce this problem only using Rust 1.64.0 and 1.65.0,, but not 1.63.0, 1.66.0-beta.2 (0040709e3 2022-11-20), or 1.67.0-nightly (b7bc90fea 2022-11-21). So I assume it's related to a compiler bug. Also, your problem is most definitely not related to the OP's, so I'm going to close the issue. Feel free to open a new one if you continue to have problems with compilers other than 1.64.0 and 1.65.0. |
Me too, I reproduce the problem with rust 1.65. |
Hi,
since I updated my rust version on build I receive the warning that several of the mocked functions are never used, such as
Is there a way to fix/suppress that warning?
The text was updated successfully, but these errors were encountered: