import pytest
# 時間の固定 ※ pytest-freezegunのインストールが必要
@pytest.mark.freeze_time('2018-01-01 11:22:33')
def test_time():
assert datetime.today() == datetime(2018, 1, 1, 11, 22, 33)
# ログ出力の内容をテスト ※ handlerなどのテスト時に使える
def test_logger_with_fixture(caplog):
# ログ出力の部分は適当に書いてて、ニュアンスだけ読み取ってほしい
import logger
logger.info('Hoge!')
assert 'Hoge!' in caplog.text
# 特定のメソッドをモックしたい (例はbugsnagのnotifyメソッドの戻り値をNoneしたい例)
@pytest.fixture
def fixture_bugsnag(monkeypatch):
def retrun_none(*args, **kwargs):
return None
monkeypatch.setattr(bugsnag.Client, "notify", retrun_none)