16
16
skip = False or skip_openai
17
17
18
18
19
- def get_current_autogen_env_var ():
20
- return os .environ .get ("AUTOGEN_USE_DOCKER" , None )
21
-
22
-
23
- def restore_autogen_env_var (current_env_value ):
24
- if current_env_value is None :
25
- del os .environ ["AUTOGEN_USE_DOCKER" ]
26
- else :
27
- os .environ ["AUTOGEN_USE_DOCKER" ] = current_env_value
28
-
29
-
30
19
def docker_running ():
31
20
return is_docker_running () or in_docker_container ()
32
21
@@ -54,32 +43,36 @@ def test_agent_setup_with_use_docker_false():
54
43
55
44
56
45
@pytest .mark .skipif (skip , reason = "openai not installed" )
57
- def test_agent_setup_with_env_variable_false_and_docker_running ():
58
- current_env_value = get_current_autogen_env_var ( )
46
+ def test_agent_setup_with_env_variable_false_and_docker_running (monkeypatch ):
47
+ monkeypatch . setenv ( "AUTOGEN_USE_DOCKER" , "False" )
59
48
60
- os .environ ["AUTOGEN_USE_DOCKER" ] = "False"
61
49
user_proxy = UserProxyAgent (
62
50
name = "test_agent" ,
63
51
human_input_mode = "NEVER" ,
64
52
)
65
53
66
54
assert user_proxy ._code_execution_config ["use_docker" ] is False
67
55
68
- restore_autogen_env_var (current_env_value )
69
-
70
56
71
57
@pytest .mark .skipif (skip or (not docker_running ()), reason = "openai not installed OR docker not running" )
72
- def test_agent_setup_with_default_and_docker_running ():
58
+ def test_agent_setup_with_default_and_docker_running (monkeypatch ):
59
+ monkeypatch .delenv ("AUTOGEN_USE_DOCKER" , raising = False )
60
+
61
+ assert os .getenv ("AUTOGEN_USE_DOCKER" ) is None
62
+
73
63
user_proxy = UserProxyAgent (
74
64
name = "test_agent" ,
75
65
human_input_mode = "NEVER" ,
76
66
)
77
67
68
+ assert os .getenv ("AUTOGEN_USE_DOCKER" ) is None
69
+
78
70
assert user_proxy ._code_execution_config ["use_docker" ] is True
79
71
80
72
81
73
@pytest .mark .skipif (skip or (docker_running ()), reason = "openai not installed OR docker running" )
82
- def test_raises_error_agent_setup_with_default_and_docker_not_running ():
74
+ def test_raises_error_agent_setup_with_default_and_docker_not_running (monkeypatch ):
75
+ monkeypatch .delenv ("AUTOGEN_USE_DOCKER" , raising = False )
83
76
with pytest .raises (RuntimeError ):
84
77
UserProxyAgent (
85
78
name = "test_agent" ,
@@ -88,31 +81,23 @@ def test_raises_error_agent_setup_with_default_and_docker_not_running():
88
81
89
82
90
83
@pytest .mark .skipif (skip or (docker_running ()), reason = "openai not installed OR docker running" )
91
- def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running ():
92
- current_env_value = get_current_autogen_env_var ()
93
-
94
- os .environ ["AUTOGEN_USE_DOCKER" ] = "True"
84
+ def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running (monkeypatch ):
85
+ monkeypatch .setenv ("AUTOGEN_USE_DOCKER" , "True" )
95
86
96
87
with pytest .raises (RuntimeError ):
97
88
UserProxyAgent (
98
89
name = "test_agent" ,
99
90
human_input_mode = "NEVER" ,
100
91
)
101
92
102
- restore_autogen_env_var (current_env_value )
103
-
104
93
105
94
@pytest .mark .skipif (skip or (not docker_running ()), reason = "openai not installed OR docker not running" )
106
- def test_agent_setup_with_env_variable_true_and_docker_running ():
107
- current_env_value = get_current_autogen_env_var ()
108
-
109
- os .environ ["AUTOGEN_USE_DOCKER" ] = "True"
95
+ def test_agent_setup_with_env_variable_true_and_docker_running (monkeypatch ):
96
+ monkeypatch .setenv ("AUTOGEN_USE_DOCKER" , "True" )
110
97
111
98
user_proxy = UserProxyAgent (
112
99
name = "test_agent" ,
113
100
human_input_mode = "NEVER" ,
114
101
)
115
102
116
103
assert user_proxy ._code_execution_config ["use_docker" ] is True
117
-
118
- restore_autogen_env_var (current_env_value )
0 commit comments