Coverage for mlos_bench/mlos_bench/tests/test_with_alt_tz.py: 86%
21 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +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."""
7import os
8import sys
9from subprocess import run
10from typing import Optional
12import pytest
14from mlos_bench.tests import ZONE_NAMES
16DIRNAME = os.path.dirname(__file__)
17TZ_TEST_FILES = [
18 DIRNAME + "/environments/local/composite_local_env_test.py",
19 DIRNAME + "/environments/local/local_env_telemetry_test.py",
20 DIRNAME + "/storage/exp_load_test.py",
21 DIRNAME + "/storage/trial_telemetry_test.py",
22]
25@pytest.mark.skipif(sys.platform == "win32", reason="TZ environment variable is a UNIXism")
26@pytest.mark.parametrize(("tz_name"), ZONE_NAMES)
27@pytest.mark.parametrize(("test_file"), TZ_TEST_FILES)
28def test_trial_telemetry_alt_tz(tz_name: Optional[str], test_file: str) -> None:
29 """Run the tests under alternative default (un-named) TZ info."""
30 env = os.environ.copy()
31 if tz_name is None:
32 env.pop("TZ", None)
33 else:
34 env["TZ"] = tz_name
35 cmd = run(
36 [sys.executable, "-m", "pytest", "-n0", test_file],
37 env=env,
38 capture_output=True,
39 check=False,
40 )
41 if cmd.returncode != 0:
42 print(cmd.stdout.decode())
43 print(cmd.stderr.decode())
44 raise AssertionError(
45 f"Test(s) failed: # TZ='{tz_name}' '{sys.executable}' -m pytest -n0 '{test_file}'"
46 )