@@ -153,61 +153,61 @@ def test_set_no_file(cli):
153153
154154
155155def test_get_default_path (tmp_path ):
156- sh .cd (str (tmp_path ))
157- with open (str (tmp_path / ".env" ), "w" ) as f :
158- f .write ("a=b" )
156+ with sh .pushd (str (tmp_path )):
157+ with open (str (tmp_path / ".env" ), "w" ) as f :
158+ f .write ("a=b" )
159159
160- result = sh .dotenv ("get" , "a" )
160+ result = sh .dotenv ("get" , "a" )
161161
162- assert result == "b\n "
162+ assert result == "b\n "
163163
164164
165165def test_run (tmp_path ):
166- sh .cd (str (tmp_path ))
167- dotenv_file = str (tmp_path / ".env" )
168- with open (dotenv_file , "w" ) as f :
169- f .write ("a=b" )
166+ with sh .pushd (str (tmp_path )):
167+ dotenv_file = str (tmp_path / ".env" )
168+ with open (dotenv_file , "w" ) as f :
169+ f .write ("a=b" )
170170
171- result = sh .dotenv ("run" , "printenv" , "a" )
171+ result = sh .dotenv ("run" , "printenv" , "a" )
172172
173- assert result == "b\n "
173+ assert result == "b\n "
174174
175175
176176def test_run_with_existing_variable (tmp_path ):
177- sh .cd (str (tmp_path ))
178- dotenv_file = str (tmp_path / ".env" )
179- with open (dotenv_file , "w" ) as f :
180- f .write ("a=b" )
181- env = dict (os .environ )
182- env .update ({"LANG" : "en_US.UTF-8" , "a" : "c" })
177+ with sh .pushd (str (tmp_path )):
178+ dotenv_file = str (tmp_path / ".env" )
179+ with open (dotenv_file , "w" ) as f :
180+ f .write ("a=b" )
181+ env = dict (os .environ )
182+ env .update ({"LANG" : "en_US.UTF-8" , "a" : "c" })
183183
184- result = sh .dotenv ("run" , "printenv" , "a" , _env = env )
184+ result = sh .dotenv ("run" , "printenv" , "a" , _env = env )
185185
186- assert result == "b\n "
186+ assert result == "b\n "
187187
188188
189189def test_run_with_existing_variable_not_overridden (tmp_path ):
190- sh .cd (str (tmp_path ))
191- dotenv_file = str (tmp_path / ".env" )
192- with open (dotenv_file , "w" ) as f :
193- f .write ("a=b" )
194- env = dict (os .environ )
195- env .update ({"LANG" : "en_US.UTF-8" , "a" : "c" })
190+ with sh .pushd (str (tmp_path )):
191+ dotenv_file = str (tmp_path / ".env" )
192+ with open (dotenv_file , "w" ) as f :
193+ f .write ("a=b" )
194+ env = dict (os .environ )
195+ env .update ({"LANG" : "en_US.UTF-8" , "a" : "c" })
196196
197- result = sh .dotenv ("run" , "--no-override" , "printenv" , "a" , _env = env )
197+ result = sh .dotenv ("run" , "--no-override" , "printenv" , "a" , _env = env )
198198
199- assert result == "c\n "
199+ assert result == "c\n "
200200
201201
202202def test_run_with_none_value (tmp_path ):
203- sh .cd (str (tmp_path ))
204- dotenv_file = str (tmp_path / ".env" )
205- with open (dotenv_file , "w" ) as f :
206- f .write ("a=b\n c" )
203+ with sh .pushd (str (tmp_path )):
204+ dotenv_file = str (tmp_path / ".env" )
205+ with open (dotenv_file , "w" ) as f :
206+ f .write ("a=b\n c" )
207207
208- result = sh .dotenv ("run" , "printenv" , "a" )
208+ result = sh .dotenv ("run" , "printenv" , "a" )
209209
210- assert result == "b\n "
210+ assert result == "b\n "
211211
212212
213213def test_run_with_other_env (dotenv_file ):
0 commit comments