mirror of
https://github.com/vale981/ray
synced 2025-03-06 02:21:39 -05:00
[Train] Monkeypatch environment variables in test_json
(#21260)
If we use `os.environ` to set environment variables in tests, then our tests become coupled. By using `monkeypatch`, we can safely set environment variables while ensuring our tests remain decoupled. For more information, see the [monkeypatching documentation](https://docs.pytest.org/en/6.2.x/monkeypatch.html#monkeypatching-environment-variables).
This commit is contained in:
parent
7ce22b72ed
commit
fa4e41c5b2
1 changed files with 3 additions and 6 deletions
|
@ -59,10 +59,10 @@ class TestBackend(Backend):
|
|||
@pytest.mark.parametrize("workers_to_log", [0, None, [0, 1]])
|
||||
@pytest.mark.parametrize("detailed", [False, True])
|
||||
@pytest.mark.parametrize("filename", [None, "my_own_filename.json"])
|
||||
def test_json(ray_start_4_cpus, make_temp_dir, workers_to_log, detailed,
|
||||
filename):
|
||||
def test_json(monkeypatch, ray_start_4_cpus, make_temp_dir, workers_to_log,
|
||||
detailed, filename):
|
||||
if detailed:
|
||||
os.environ[ENABLE_DETAILED_AUTOFILLED_METRICS_ENV] = "1"
|
||||
monkeypatch.setenv(ENABLE_DETAILED_AUTOFILLED_METRICS_ENV, "1")
|
||||
|
||||
config = TestConfig()
|
||||
|
||||
|
@ -119,9 +119,6 @@ def test_json(ray_start_4_cpus, make_temp_dir, workers_to_log, detailed,
|
|||
all(not any(key in worker for key in DETAILED_AUTOFILLED_KEYS)
|
||||
for worker in element) for element in log)
|
||||
|
||||
os.environ.pop(ENABLE_DETAILED_AUTOFILLED_METRICS_ENV, 0)
|
||||
assert ENABLE_DETAILED_AUTOFILLED_METRICS_ENV not in os.environ
|
||||
|
||||
|
||||
def _validate_tbx_result(events_dir):
|
||||
events_file = list(glob.glob(f"{events_dir}/events*"))[0]
|
||||
|
|
Loading…
Add table
Reference in a new issue