Skip to content

Feature Request: Unloading function unload_dotenv() #594

Description

@nobites

Once load_dotenv() has run, variables are set. To remove them again for unit testing, I need a function, because tests should be independent. I coded this function already, but I think it would be nice to have it included in dotenv. I guess, I'm not the only one with the described problem. But maybe I'm wrong. I stepped over this more than once now. That's why I'm suggesting adding this function:

def unload_dotenv():
    """Remove all dotenv variables from environment."""

    dotenv_vars = set(dotenv_values().keys())
    for key in dotenv_vars:
        os.environ.pop(key, None)

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions