Compile error calling dotenv from test

I have an integration test, where I am trying to load dotenv::dotenv(".env.test"), but I get unexpected errors like this:

expected one of `!` or `::`, found `(`

expected one of `!` or `::`

Same error if I try this in a unit test. I can take a line of code, such as dotenv::dotenv().ok(), that works in a non-test module and move it to the test module and it fails.

#[cfg(test)]
mod tests {
    use dotenv;
    dotenv::dotenv().ok();
                 ^^^
}

The editor underlines the opening paren in dotenv as the problem, with this error:

expected one of `!` or `::`, found `(`

expected one of `!` or `::`

Does anyone see what I'm doing wrong?

I found the problem. I didn't put my code inside a function. This works.

#[cfg(test)]
mod tests {
    #[test]
    fn dothis() {
        use dotenv::dotenv;
        dotenv().ok();

    }
}