Skip to content

Commit b26d6b8

Browse files
committed
chore: simplify mock
1 parent b9857c2 commit b26d6b8

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

tests/unit/utils/test_git_shell.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22
import platform
3-
import subprocess
43
import tarfile
54
from io import BytesIO
65
from pathlib import Path
76
from typing import Optional
7+
from unittest.mock import Mock, patch
88

99
import pytest
1010

@@ -446,29 +446,14 @@ def test_git_ls_unstaged(tmp_path):
446446
assert {Path(x) for x in unstaged_files} == expected_paths
447447

448448

449-
def test_git_command_includes_longpaths_on_windows(monkeypatch):
450-
# GIVEN a mock for subprocess.run
451-
commands_run = []
452-
453-
def mock_subprocess_run(args, **kwargs):
454-
commands_run.append(args)
455-
456-
# Create a minimal mock result
457-
class Result:
458-
def __init__(self):
459-
self.stdout = b""
460-
self.stderr = b""
461-
462-
return Result()
463-
464-
monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
465-
466-
# WHEN executing any git command
449+
@patch("subprocess.run", return_value=Mock(stdout=b""))
450+
def test_git_command_includes_longpaths_on_windows(mock_run):
451+
# GIVEN any git command
467452
git(["status"])
453+
mock_run.assert_called_once()
468454

469455
# THEN the command includes core.longpaths=true if on Windows
470-
assert len(commands_run) == 1
471-
command = commands_run[0]
456+
command = mock_run.call_args[0][0]
472457
longpaths_included = any(param == "core.longpaths=true" for param in command)
473458
if platform.system() == "Windows":
474459
assert (

0 commit comments

Comments
 (0)