0

I have a script in which I start with running a function. i.e.

foo.py

from bar import some_func
some_func()

# rest of code

I want to make sure that this function will always be run first, hence I want to create a unittest which imports foo.py and assert whether its called.

I tried the following:

test_import.py

@mock.patch("foo.some_func")
def test_func_called_on_import(some_func_mock):
    import foo
    some_func_mock.assert_called_once()

But that results in an error stating it was called 0 times. Does anyone have experience in such a testcase?

Thanks in advance!

Jeroen
  • 25
  • 1
  • 6

0 Answers0