Skip to content

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

Closed

Description

@valentinegb

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?

Activity

  1. valentinegb commented on Jan 15, 2023

    @valentinegb
    Author

    Right now I'm just doing this:

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

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

  2. allan2 commented on Jan 15, 2023

    @allan2
    Owner

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

    dotenv().ok(); // discards the error if there is one
  3. valentinegb commented on Jan 15, 2023

    @valentinegb
    Author

    Oh- yeah, duh, thanks lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions