Skip to content

env attribute of *_test rules should be able to overwrite variables like PATH #14418

@martis42

Description

@martis42

Description of the problem / feature request:

The test rule attribute env should be able to overwrite environment variables, not just inject additional ones.

Feature requests: what underlying problem are you trying to solve with this feature?

I am writing tests which require a custom PATH value.
One could modify the PATH environment variable inside the test implementation, but I consider this a hacky workaround.

--test_env can do the required task, but it influences all tests, whereas I want to influence just some specific tests.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

BUILD file

sh_test(
    name = "foo",
    srcs = ["foo.sh"],
    env = {
        "PATH": "foo",
        "FOO": "bar",
    },
)

test implementation

#!/usr/bin/env bash
echo $PATH
echo $FOO

command: bazel test --test_output=all //:foo

The test will not print the expected foo.

What operating system are you running Bazel on?

Ubuntu 20.04

What's the output of bazel info release?

release 4.1.0

Have you found anything relevant by searching the web?

The documentation explicitly states Specifies additional environment ....
It seems the current behavior is intended. Still, I believe being able to overwrite PATH is a valid feature.
No open issues discussing overwriting environment variables could be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4This is either out of scope or we don't have bandwidth to review a PR. (No assignee)team-Rules-ServerIssues for serverside rules included with Bazeltype: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions