[Python] Python unittest AssertionError: Calls not found

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I try to run a unit test, in a yaml file for possible values in a config file I have changed

    flashing: single|enum(off,all,match,mask,not_set)|not_set


    to

    flashing: single|enum(off,all,match,mask,not_set)|off


    no code change, no nothing else. Before the change the unit test run fine, now it throws an error:

    Traceback (most recent call last): File "C:\Users\d\AppData\Local\Programs\Python\Python312\Lib\unittest\mock.py", line 1396, in patched
    return func(*newargs, **newkeywargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\d\mpfenv2\Lib\site-packages\mpf\tests\test_SegmentDisplay.py", line 1126, in test_transitions_with_player
    mock_set_text.assert_has_calls([ File "C:\Users\d\AppData\Local\Programs\Python\Python312\Lib\unittest\mock.py", line 986, in assert_has_calls
    raise AssertionError( AssertionError: Calls not found.


    It doesn't seem to be a "normal" unit test error where a check is failing, the relevant part of the unit test should be

    @patch("mpf.platforms.virtual.VirtualSegmentDisplay.set_text")
    def test_transitions_with_player(self, mock_set_text):
    red = RGBColor("red")
    wht = RGBColor("white")
    self.post_event("test_set_color_to_red")
    self.advance_time_and_run(1)

    mock_set_text.assert_has_calls(
    [call(
    SegmentDisplayText.from_str_with_color(' ', 7, True, True, False, [red] * 7),
    flash_mask='', flashing=FlashingType.NO_FLASH)])
    mock_set_text.reset_mock()


    I tried to understand what the mock and the @patch is doing, but to be frank I failed to understand what I found on the net. It is only a gut feeling that this is related, might be on the wrong path. Any hint into what direction I can investigate how to fix the issue?

    Continue reading...

Compartilhe esta Página