Coverage for mlos_bench/mlos_bench/tests/test_with_alt_tz.py: 85%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-21 01:50 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Tests various other test scenarios with alternative default (un-named) TZ info.""" 

6 

7import os 

8import sys 

9from subprocess import run 

10 

11import pytest 

12 

13from mlos_bench.tests import ZONE_NAMES 

14 

15DIRNAME = os.path.dirname(__file__) 

16TZ_TEST_FILES = [ 

17 DIRNAME + "/environments/local/composite_local_env_test.py", 

18 DIRNAME + "/environments/local/local_env_telemetry_test.py", 

19 DIRNAME + "/storage/exp_load_test.py", 

20 DIRNAME + "/storage/trial_telemetry_test.py", 

21] 

22 

23 

24@pytest.mark.skipif(sys.platform == "win32", reason="TZ environment variable is a UNIXism") 

25@pytest.mark.parametrize(("tz_name"), ZONE_NAMES) 

26@pytest.mark.parametrize(("test_file"), TZ_TEST_FILES) 

27def test_trial_telemetry_alt_tz(tz_name: str | None, test_file: str) -> None: 

28 """Run the tests under alternative default (un-named) TZ info.""" 

29 env = os.environ.copy() 

30 if tz_name is None: 

31 env.pop("TZ", None) 

32 else: 

33 env["TZ"] = tz_name 

34 cmd = run( 

35 [sys.executable, "-m", "pytest", "-n0", test_file], 

36 env=env, 

37 capture_output=True, 

38 check=False, 

39 ) 

40 if cmd.returncode != 0: 

41 print(cmd.stdout.decode()) 

42 print(cmd.stderr.decode()) 

43 raise AssertionError( 

44 f"Test(s) failed: # TZ='{tz_name}' '{sys.executable}' -m pytest -n0 '{test_file}'" 

45 )