From bf1eb648cdea9712898d0e9fab594f218a2c3bbb Mon Sep 17 00:00:00 2001 From: zhihao11ui Date: Tue, 8 Oct 2024 23:42:41 -0500 Subject: [PATCH] Fixed test_cmd_path flaky test --- tests/test_system.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/test_system.py b/tests/test_system.py index c148523..0897ce7 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -352,13 +352,17 @@ def test_dir_cmd(self, mycmd): assert which(mycmd) == mycmd def test_cmd_path(self, tmpdir, mycmd): - path = str(tmpdir) - assert which('mycmd') is None - assert which('mycmd', path=path) == mycmd - - os.environ['PATH'] = path + os.pathsep + \ - os.environ.get('PATH', os.defpath) - assert which('mycmd') == mycmd + original_path = os.environ['PATH'] + try: + path = str(tmpdir) + assert which('mycmd') is None + assert which('mycmd', path=path) == mycmd + + os.environ['PATH'] = path + os.pathsep + \ + os.environ.get('PATH', os.defpath) + assert which('mycmd') == mycmd + finally: + os.environ['PATH'] = original_path @pytest.mark.skipif(not WINDOWS, reason='Not support non Windows')