Skip to content

Commit 974144b

Browse files
kiukchungfacebook-github-bot
authored andcommitted
Prevent //torchx/cli/test:cmd_run_test from picking up user's /home/kiuk/.torchxconfig when running test cases
Summary: Fix flaky `//torchx/cli/test:cmd_run_test` when running on devserver where a user (`$HOME/.torchxconfig`) torchxconfig file exists and was being picked up by the test therefore failing assertions. Differential Revision: D73208636
1 parent bec9317 commit 974144b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

torchx/cli/test/cmd_run_test.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from unittest.mock import MagicMock, patch
2222

2323
from torchx.cli.argparse_util import ArgOnceAction, torchxconfig
24-
2524
from torchx.cli.cmd_run import _parse_component_name_and_args, CmdBuiltins, CmdRun
2625
from torchx.schedulers.local_scheduler import SignalException
2726

@@ -216,38 +215,41 @@ def test_store_experiment_id(self, mock_runner_run: MagicMock) -> None:
216215
self.assertEqual(call_kwargs["parent_run_id"], "experiment_1")
217216

218217
def test_parse_component_name_and_args_no_default(self) -> None:
218+
# set dirs to test tmpdir so tests don't accidentally pick up user's $HOME/.torchxconfig
219+
dirs = [str(self.tmpdir)]
220+
219221
sp = argparse.ArgumentParser(prog="test")
220222
self.assertEqual(
221223
("utils.echo", []),
222-
_parse_component_name_and_args(["utils.echo"], sp),
224+
_parse_component_name_and_args(["utils.echo"], sp, dirs),
223225
)
224226
self.assertEqual(
225227
("utils.echo", []),
226-
_parse_component_name_and_args(["--", "utils.echo"], sp),
228+
_parse_component_name_and_args(["--", "utils.echo"], sp, dirs),
227229
)
228230
self.assertEqual(
229231
("utils.echo", ["--msg", "hello"]),
230-
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp),
232+
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp, dirs),
231233
)
232234

233235
self.assertEqual(
234236
("utils.echo", ["--msg", "hello", "--", "--"]),
235237
_parse_component_name_and_args(
236-
["utils.echo", "--msg", "hello", "--", "--"], sp
238+
["utils.echo", "--msg", "hello", "--", "--"], sp, dirs
237239
),
238240
)
239241

240242
self.assertEqual(
241243
("utils.echo", ["--msg", "hello", "-", "-"]),
242244
_parse_component_name_and_args(
243-
["utils.echo", "--msg", "hello", "-", "-"], sp
245+
["utils.echo", "--msg", "hello", "-", "-"], sp, dirs
244246
),
245247
)
246248

247249
self.assertEqual(
248250
("utils.echo", ["--msg", "hello", "- ", "- "]),
249251
_parse_component_name_and_args(
250-
["utils.echo", "--msg", "hello", "- ", "- "], sp
252+
["utils.echo", "--msg", "hello", "- ", "- "], sp, dirs
251253
),
252254
)
253255

@@ -274,32 +276,35 @@ def test_parse_component_name_and_args_no_default(self) -> None:
274276
"-m",
275277
],
276278
sp,
279+
dirs,
277280
),
278281
)
279282

280283
with self.assertRaises(SystemExit):
281-
_parse_component_name_and_args(["--"], sp)
284+
_parse_component_name_and_args(["--"], sp, dirs)
282285

283286
with self.assertRaises(SystemExit):
284-
_parse_component_name_and_args(["--msg", "hello"], sp)
287+
_parse_component_name_and_args(["--msg", "hello"], sp, dirs)
285288

286289
with self.assertRaises(SystemExit):
287-
_parse_component_name_and_args(["-m", "hello"], sp)
290+
_parse_component_name_and_args(["-m", "hello"], sp, dirs)
288291

289292
with self.assertRaises(SystemExit):
290-
_parse_component_name_and_args(["-m", "hello", "-m", "repeate"], sp)
293+
_parse_component_name_and_args(["-m", "hello", "-m", "repeate"], sp, dirs)
291294

292295
with self.assertRaises(SystemExit):
293-
_parse_component_name_and_args(["--msg", "hello", "--msg", "repeate"], sp)
296+
_parse_component_name_and_args(
297+
["--msg", "hello", "--msg", "repeate"], sp, dirs
298+
)
294299

295300
with self.assertRaises(SystemExit):
296301
_parse_component_name_and_args(
297-
["--msg ", "hello", "--msg ", "repeate"], sp
302+
["--msg ", "hello", "--msg ", "repeate"], sp, dirs
298303
)
299304

300305
with self.assertRaises(SystemExit):
301306
_parse_component_name_and_args(
302-
["--m", "hello", "--", "--msg", "msg", "--msg", "repeate"], sp
307+
["--m", "hello", "--", "--msg", "msg", "--msg", "repeate"], sp, dirs
303308
)
304309

305310
def test_parse_component_name_and_args_with_default(self) -> None:

0 commit comments

Comments
 (0)