AcademySoftwareFoundation / AcademySoftwareFoundation/rez

Add an environment environment to indicate the current Rez test being executed

Open
#1,261 2 comments 0 reactions 0 assignees View on GitHub
enhancement rez-test
Dominant language
Python
Stars
1.1k
Forks
374
Avg merge
9d 12h
Merged PRs (30d)
5

Description

When running tests, such as `rez-test package_name foo bar fizz buzz`, for each test ran, I would like Rez to give an environment variable indicating the test which is running. It could be called `REZ_CURRENT_TEST_NAME` or something similarly named.

**Motivation**
The Rez package I'm writing is intended to be called in **other** Rez packages, as a `rez-test` command. Part of that command's work must query the `requires` of the rez-test which is executing. I'm getting by with `REZ_USED_REQUEST` right now and deleting the current package name from that list to get the "list of `requires` of that test". However that has a problem. `rez-test` has a `--extra-packages` flag, which directly appends to `REZ_USED_REQUEST`. So now that list isn't 100% the `requires` list and that causes problems downstream.

I see in [package_test.py](https://github.com/nerdvegas/rez/blob/fa3fff6f0b7b4b53bbb9baa4357ab42117d06356/src/rez/package_test.py#L429-L432), there's a `test` bound variable for `pre_test_commands`. Could we please apply that as an environment variable during regular testing?

The only way I can replicate the behavior that I need currently is to add

```python
def pre_test_commands():
env.REZ_CURRENT_TEST_NAME.set(test)
```

but this project, as mentioned, is being included in other Rez packages. So users would have to add that `pre_test_commands` everywhere that they use my package, and it's used in many places. A simple, targeted environment variable would be a big help.

Contributor guide

Open the contributing guide

Research direction

The test setup is discussed in src/rez/package_test.py around lines 429-432, where the test-bound value is used for pre_test_commands. Start there and run a rez-test invocation covering a package test; done means each running test exposes its name through an environment variable without requiring users to add pre_test_commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.