|
| 1 | +import os |
| 2 | + |
| 3 | + |
| 4 | +def test_grpc_verbosity_set_on_import(): |
| 5 | + """ |
| 6 | + Test that GRPC_VERBOSITY is set to NONE if not already present in the environment |
| 7 | + when the SDK container module is imported. |
| 8 | + """ |
| 9 | + original_value = os.environ.get("GRPC_VERBOSITY", None) |
| 10 | + |
| 11 | + try: |
| 12 | + if "GRPC_VERBOSITY" in os.environ: |
| 13 | + del os.environ["GRPC_VERBOSITY"] |
| 14 | + |
| 15 | + import importlib |
| 16 | + import flytekit.clis.sdk_in_container |
| 17 | + importlib.reload(flytekit.clis.sdk_in_container) |
| 18 | + |
| 19 | + assert "GRPC_VERBOSITY" in os.environ |
| 20 | + assert os.environ["GRPC_VERBOSITY"] == "NONE" |
| 21 | + |
| 22 | + finally: |
| 23 | + if original_value is not None: |
| 24 | + os.environ["GRPC_VERBOSITY"] = original_value |
| 25 | + elif "GRPC_VERBOSITY" in os.environ: |
| 26 | + del os.environ["GRPC_VERBOSITY"] |
| 27 | + |
| 28 | + |
| 29 | +def test_grpc_verbosity_not_overridden(): |
| 30 | + """ |
| 31 | + Test that GRPC_VERBOSITY is not overridden if already set in the environment. |
| 32 | + """ |
| 33 | + original_value = os.environ.get("GRPC_VERBOSITY", None) |
| 34 | + |
| 35 | + try: |
| 36 | + os.environ["GRPC_VERBOSITY"] = "INFO" |
| 37 | + |
| 38 | + import importlib |
| 39 | + import flytekit.clis.sdk_in_container |
| 40 | + importlib.reload(flytekit.clis.sdk_in_container) |
| 41 | + |
| 42 | + assert os.environ["GRPC_VERBOSITY"] == "INFO" |
| 43 | + |
| 44 | + finally: |
| 45 | + if original_value is not None: |
| 46 | + os.environ["GRPC_VERBOSITY"] = original_value |
| 47 | + elif "GRPC_VERBOSITY" in os.environ: |
| 48 | + del os.environ["GRPC_VERBOSITY"] |
0 commit comments