allan2 / dotenvy

A well-maintained fork of the dotenv crate
MIT License
688 stars 43 forks source link

How do you make a test that doesn't fail if `dotenv()` doesn't find the `.env` file? #62

Closed valentinegb closed 1 year ago

valentinegb commented 1 year ago

In my Rust program, I have a .env file for my environmental variables when I run the tests on my computer. However, I also run the tests via a GitHub workflow, where I have a repository secret defined. Currently, these tests all fail in the workflow because there is no .env file present. How should I resolve this?

valentinegb commented 1 year ago

Right now I'm just doing this:

#![allow(unused_must_use)]
dotenv();

But I'd rather not have to disable any warnings.

allan2 commented 1 year ago

dotenv() returns Result. You can handle the error or ignore it.

dotenv().ok(); // discards the error if there is one
valentinegb commented 1 year ago

Oh- yeah, duh, thanks lol