ConfigObjを使用して、いくつかのセクション作成コードをテストしたいと思います。
def create_section(config, section):
config.reload()
if section not in config:
config[session] = {}
logging.info("Created new section %s.", section)
else:
logging.debug("Section %s already exists.", section)
いくつかの単体テストを書きたいのですが、問題が発生しています。例えば、
def test_create_section_created():
config = Mock(spec=ConfigObj) # ← This is not right…
create_section(config, 'ook')
assert 'ook' in config
config.reload.assert_called_once_with()
明らかに、TypeError
型 'Mock' の引数が反復可能でないため、テスト メソッドは失敗します。
config
オブジェクトをモックとして定義するにはどうすればよいですか?