Skip to content

No way to unset environment variables #7790

@rossmacarthur

Description

@rossmacarthur

Describe the problem you are trying to solve

I would like to unset environment variables when tests are run.

I need this because I have tests for a CLI program (it uses structopt) and if the environment I'm running in has certain environment variables set it can interfere with the tests.

Describe the solution you'd like

I first tried to remove the environment variables in a build script using std::env::remove_var("VAR") but that didn't work.

Then tried to do this in a build script using cargo:rustc-env=VAR= however this still sets it to an empty string. So a similar option like cargo:rustc-remove-env=VAR would be nice. Of course a way to run some code before tests are run could also solve this.

So now I have to remove the environment variables in every test :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions