Skip to content

Commit 3b4590f

Browse files
committed
fix: replace os.startfile with subprocess.run to resolve pylint warning
1 parent 39f9cb2 commit 3b4590f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

tests/test_pathbrowser.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,22 @@ def test_open_file_with_default_app_windows(self):
259259
with patch('tkface.widget.pathbrowser.utils.IS_WINDOWS', True):
260260
with patch('tkface.widget.pathbrowser.utils.IS_MACOS', False):
261261
with patch('tkface.widget.pathbrowser.utils.IS_LINUX', False):
262-
# Mock os.startfile by patching the module directly with create=True
263-
with patch('os.startfile', create=True) as mock_startfile:
262+
with patch('tkface.widget.pathbrowser.utils.subprocess.run') as mock_run:
264263
result = utils.open_file_with_default_app("C:\\test\\file.txt")
265264
assert result is True
266-
mock_startfile.assert_called_once_with("C:\\test\\file.txt")
265+
mock_run.assert_called_once_with(
266+
["cmd", "/c", "start", "", "C:\\test\\file.txt"],
267+
check=False,
268+
shell=False
269+
)
267270

268271
def test_open_file_with_default_app_windows_exception(self):
269272
"""Test open_file_with_default_app function on Windows with exception."""
270273
with patch('tkface.widget.pathbrowser.utils.IS_WINDOWS', True):
271274
with patch('tkface.widget.pathbrowser.utils.IS_MACOS', False):
272275
with patch('tkface.widget.pathbrowser.utils.IS_LINUX', False):
273-
# Mock os.startfile by patching the module directly with create=True
274-
with patch('os.startfile', create=True) as mock_startfile:
275-
mock_startfile.side_effect = Exception("Access denied")
276+
with patch('tkface.widget.pathbrowser.utils.subprocess.run') as mock_run:
277+
mock_run.side_effect = Exception("Access denied")
276278
result = utils.open_file_with_default_app("C:\\test\\file.txt")
277279
assert result is False
278280

tkface/widget/pathbrowser/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def open_file_with_default_app(file_path: str) -> bool:
5555
"""
5656
try:
5757
if IS_WINDOWS:
58-
os.startfile(file_path) # pylint: disable=no-member
58+
# Use subprocess instead of os.startfile to avoid shell process warning
59+
subprocess.run(["cmd", "/c", "start", "", file_path], check=False, shell=False)
5960
elif IS_MACOS:
6061
open_cmd = shutil.which("open")
6162
if open_cmd:

0 commit comments

Comments
 (0)