mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Merge pull request #3584 from pre-commit/exitstack
Some checks are pending
Some checks are pending
use ExitStack instead of start + stop
This commit is contained in:
commit
e436690f14
1 changed files with 4 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import os.path
|
import os.path
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
|
@ -97,11 +98,9 @@ CMDS = tuple(fn.replace('_', '-') for fn in FNS)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_commands():
|
def mock_commands():
|
||||||
mcks = {fn: mock.patch.object(main, fn).start() for fn in FNS}
|
with contextlib.ExitStack() as ctx:
|
||||||
ret = auto_namedtuple(**mcks)
|
mcks = {f: ctx.enter_context(mock.patch.object(main, f)) for f in FNS}
|
||||||
yield ret
|
yield auto_namedtuple(**mcks)
|
||||||
for mck in ret:
|
|
||||||
mck.stop()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue