I am trying to mock out a class that is being called/initialised in a function.
def example_function():
example_class = SomeClass(my_position, num_list, suit_list)
@mock.patch('.../SomeClass')
def test_example_function(mock_SomeClass):
example_function()
When I run the above, I get:
NameError: name 'my_position' is not defined
However, I know that SomeClass
is being mocked out, because if I set a breakpoint()
in the line just above example_class = SomeClass(my_position, num_list, suit_list)
And print out SomeClass
it says:
<MagicMock name='ShouldWePlayThisPreFlopHand' id='139711184614096'>
Any ideas how I can overcome this?
Some additional information: I am defining my_position
as a global variable within the python package of example_function()
.
So when I run a unit test, my_position
is not initialised/set.
3