Skip to content

Commit bf6c8b7

Browse files
committed
Fix test_utils_functions sys.argv handling
Tests were failing because they created temp files but get_added_files() looks for files in sys.argv, not in the args attribute. Fixed by temporarily modifying sys.argv in the test setUp to simulate command-line arguments properly. Tests now pass: - test_get_added_files_from_argv - test_cfg_files_filtered_out
1 parent f04963d commit bf6c8b7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tests/test_utils_functions.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@ def test_get_added_files_from_argv(self):
4040
temp_file = f.name
4141

4242
try:
43+
# Temporarily modify sys.argv to simulate command-line args
44+
import sys
45+
original_argv = sys.argv
46+
sys.argv = ["test-cmd", temp_file]
4347

4448
class TestCmd(Command):
4549
def __init__(self):
4650
self.command = "test"
4751
self.look_behind = "test"
48-
self.args = ["test-cmd", temp_file]
52+
self.args = sys.argv
4953
self.files = self.get_added_files()
5054

5155
cmd = TestCmd()
5256
assert temp_file in cmd.files
5357
finally:
58+
sys.argv = original_argv
5459
if os.path.exists(temp_file):
5560
os.unlink(temp_file)
5661

@@ -67,18 +72,23 @@ def test_cfg_files_filtered_out(self):
6772
c_path = c_file.name
6873

6974
try:
75+
# Temporarily modify sys.argv to simulate command-line args
76+
import sys
77+
original_argv = sys.argv
78+
sys.argv = ["test-cmd", cfg_path, c_path]
7079

7180
class TestCmd(Command):
7281
def __init__(self):
7382
self.command = "test"
7483
self.look_behind = "test"
75-
self.args = ["test-cmd", cfg_path, c_path]
84+
self.args = sys.argv
7685
self.files = self.get_added_files()
7786

7887
cmd = TestCmd()
7988
assert cfg_path not in cmd.files
8089
assert c_path in cmd.files
8190
finally:
91+
sys.argv = original_argv
8292
if os.path.exists(cfg_path):
8393
os.unlink(cfg_path)
8494
if os.path.exists(c_path):

0 commit comments

Comments
 (0)