Skip to content

Commit

Permalink
error handling: move import block into try block
Browse files Browse the repository at this point in the history
  • Loading branch information
questcollector committed Oct 16, 2024
1 parent d3f9fe4 commit 03de569
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions test/coding/test_kubernetes_commandline_code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import pytest

client = importlib.import_module("kubernetes.client")
config = importlib.import_module("kubernetes.config")

from autogen.code_utils import TIMEOUT_MSG
from autogen.coding.base import CodeBlock, CodeExecutor

try:
from autogen.coding.kubernetes import PodCommandLineCodeExecutor

client = importlib.import_module("kubernetes.client")
config = importlib.import_module("kubernetes.config")

kubeconfig = Path(".kube/config")
if os.environ.get("KUBECONFIG", None):
kubeconfig = Path(os.environ["KUBECONFIG"])
Expand All @@ -29,33 +29,34 @@
skip_kubernetes_tests = False
else:
skip_kubernetes_tests = True
except Exception:
skip_kubernetes_tests = True


pod_spec = client.V1Pod(
metadata=client.V1ObjectMeta(name="abcd", namespace="default", annotations={"sidecar.istio.io/inject": "false"}),
spec=client.V1PodSpec(
restart_policy="Never",
containers=[
client.V1Container(
args=["-c", "while true;do sleep 5; done"],
command=["/bin/sh"],
name="abcd",
image="python:3.11-slim",
env=[
client.V1EnvVar(name="TEST", value="TEST"),
client.V1EnvVar(
name="POD_NAME",
value_from=client.V1EnvVarSource(
field_ref=client.V1ObjectFieldSelector(field_path="metadata.name")
pod_spec = client.V1Pod(
metadata=client.V1ObjectMeta(
name="abcd", namespace="default", annotations={"sidecar.istio.io/inject": "false"}
),
spec=client.V1PodSpec(
restart_policy="Never",
containers=[
client.V1Container(
args=["-c", "while true;do sleep 5; done"],
command=["/bin/sh"],
name="abcd",
image="python:3.11-slim",
env=[
client.V1EnvVar(name="TEST", value="TEST"),
client.V1EnvVar(
name="POD_NAME",
value_from=client.V1EnvVarSource(
field_ref=client.V1ObjectFieldSelector(field_path="metadata.name")
),
),
),
],
)
],
),
)
],
)
],
),
)
except Exception:
skip_kubernetes_tests = True


@pytest.mark.skipif(skip_kubernetes_tests, reason="kubernetes not accessible")
Expand Down

0 comments on commit 03de569

Please sign in to comment.