| 12345678910111213141516171819202122232425262728293031323334353637 |
- import logging
- import pytest
- import subprocess
- import typing
- import unittest.mock
- from cipy import _handler
- from mocks import mock_run
- @pytest.fixture(scope="function")
- def mock_subprocess() -> typing.Iterator[unittest.mock.Mock]:
- mock = unittest.mock.Mock()
- def run(*args, **kwargs):
- return mock_run(
- *args,
- **kwargs,
- _poison_stdout=mock.stdout.encode("utf-8"),
- _poison_stderr=mock.stderr.encode("utf-8"),
- )
- mock.side_effect = run
- mock.stderr = ""
- mock.stdout = ""
- with unittest.mock.patch("subprocess.run", mock):
- yield mock
- @pytest.fixture(scope="function")
- def ci_logger(monkeypatch: pytest.MonkeyPatch) -> typing.Iterator[unittest.mock.Mock]:
- mock = unittest.mock.Mock(spec=logging.Formatter)
- monkeypatch.setattr(_handler, "formatter", mock)
- level = logging.getLogger().level
- logging.getLogger().setLevel(logging.NOTSET)
- yield mock
- logging.getLogger().setLevel(level)
|