I'm doing the 100 days of Python videos and I'm trying to reproduce the pytest example form https://github.com/talkpython/100daysofcode-with-python-course/tree/master/days/10-12-pytest/guess to make sure I understood it. But it doesn't work, even though I think I copied it 1-to-1 (when I run the code from the github, it works, for some reason).

The 3 files below are my reproduction - but the test fails unfortunately. Where is my error?

#scratch_module.py

def dumbfunc():
    return "I'm just a simple function."

and

#scratch.py
from scratch_module import dumbfunc


def myfunc():
    str = dumbfunc()
    return str + " HI, I'M MYFUNC!!!"


print(myfunc())

and

#test_scratch.py

from unittest.mock import patch

import scratch_module
import pytest
from scratch import myfunc


@patch.object(scratch_module, 'dumbfunc')
def test_myfunc(mock_method):
    mock_method.return_value = "MOCKED OUT! OK!"
    obs = myfunc()
    exp = "MOCKED OUT! OK! HI, I'M MYFUNC!!!"
    assert obs == exp

0 Answers