2016-09-20 2 views
1

ConfigObj 사용하여, 나는 몇 가지 section 생성 코드를 테스트하려는. 유형의 인수로 TypeError의 '모의'가 반복 가능하지 않기 때문에 예를 들어,비웃음 ConfigObj 인스턴스

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() 

분명히, 시험 방법은 실패합니다.

config 객체를 모의 객체로 정의하려면 어떻게해야합니까?

답변

0

그리고 이것은 왜 안입니다, , 후 당신이 깨어 전에 : 나는 경우 다른 사람의 후손 여기 그 해답/질문을 떠나서

def test_create_section_created(): 
    logger.info = Mock() 
    config = MagicMock(spec=ConfigObj) # ← This IS right… 
    config.__contains__.return_value = False # Negates the next assert. 
    create_section(config, 'ook') 
    # assert 'ook' in config ← This is now a pointless assert! 
    config.reload.assert_called_once_with() 
    logger.info.assert_called_once_with("Created new section ook.") 

는 뇌 장애를 가지고 ...