Merge pull request #3584 from pre-commit/exitstack
Some checks are pending
languages / vars (push) Waiting to run
languages / language (push) Blocked by required conditions
languages / collector (push) Blocked by required conditions
main / main-windows (push) Waiting to run
main / main-linux (push) Waiting to run

use ExitStack instead of start + stop
This commit is contained in:
anthony sottile 2025-11-21 15:19:53 -05:00 committed by GitHub
commit e436690f14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import argparse
import contextlib
import os.path
from unittest import mock
@ -97,11 +98,9 @@ CMDS = tuple(fn.replace('_', '-') for fn in FNS)
@pytest.fixture
def mock_commands():
mcks = {fn: mock.patch.object(main, fn).start() for fn in FNS}
ret = auto_namedtuple(**mcks)
yield ret
for mck in ret:
mck.stop()
with contextlib.ExitStack() as ctx:
mcks = {f: ctx.enter_context(mock.patch.object(main, f)) for f in FNS}
yield auto_namedtuple(**mcks)
@pytest.fixture