Skip to content

Why ever assert == the same object as return_value?  #3

Description

@gitgithan
def test_person_class_with_mock(mocker):
    """
    Test the Person class using a mock for the 'get_person_json' method 
    """
    person = Person(name="Eric", age=25, address="123 Farmville Rd")
    mock_response = {"name": "FAKE_NAME", "age": "FAKE_AGE", "address": "FAKE_ADDRESS"}

    # Patch the method
    mocker.patch.object(person, "get_person_json", return_value=mock_response)

    assert person.get_person_json() == mock_response

I could not understand the combination of return_value=mock_response) and assert person.get_person_json() == mock_response

It seems like no matter how get_person_json is implemented, the return_value is forced to equal mock_response, then of course the assert will be True, making this test redundant.

Why ever do this pattern? What is it testing?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions