Skip to content

Commit 8d34f95

Browse files
committed
use ExitStack instead of start + stop
1 parent 9c7ea88 commit 8d34f95

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/main_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import argparse
4+
import contextlib
45
import os.path
56
from unittest import mock
67

@@ -97,11 +98,9 @@ def test_adjust_args_try_repo_repo_relative(in_git_dir):
9798

9899
@pytest.fixture
99100
def mock_commands():
100-
mcks = {fn: mock.patch.object(main, fn).start() for fn in FNS}
101-
ret = auto_namedtuple(**mcks)
102-
yield ret
103-
for mck in ret:
104-
mck.stop()
101+
with contextlib.ExitStack() as ctx:
102+
mcks = {f: ctx.enter_context(mock.patch.object(main, f)) for f in FNS}
103+
yield auto_namedtuple(**mcks)
105104

106105

107106
@pytest.fixture

0 commit comments

Comments
 (0)