grappa-py / grappa

Behavior-oriented, expressive, human-friendly Python assertion library for the 21st century
http://grappa.rtfd.io
MIT License
134 stars 15 forks source link

Allow usage of any subject attribute renderer messages #62

Closed sgissinger closed 3 years ago

sgissinger commented 3 years ago

I propose this because I'm doing custom operator to wrap unit test mocks assertions.

And I wanted to display the number of call count which is an attribute of MagicMock object.

    expected_message = Operator.Dsl.Message(
        'a mock that has been called {value} times',
        'a mock that has not been called {value} times',
    )
    subject_message = Operator.Dsl.Message(
        'a mock that has been called {%call_count%} times',
        'a mock that has not been called {%call_count%} times',
    )

When {value} is used in subject_message it prints the repr() value

<MagicMock name='get_service_state.name' id='1897037976184'>
sgissinger commented 3 years ago

Used another way in #64