I want to test a function like this, with pytest:
def asdf():
a = first_function()
b = second_function()
where a has a block like this:
result_queue_first = queue.Queue()
result_queue_second = queue.Queue()
first_thread = threading.Thread(target=myfunction1, args=(result_queue_first))
first_thread.start()
second_thread = threading.Thread(target=myfunction2, args=(result_queue_second))
second_thread.start()
first_thread.join()
result_first = result_queue_first.get()
second_thread.join()
result_second = result_queue_second.get()
and b
has inside a function that calculates something and assigns it to a variable
When I try to mock asdf
using @patch
@patch(path.to.function.asdf)
def test_function(example):
example.return_value = 'value'
<sentences of the test>
I get this error
TypeError: 'coroutine' object does not support item assignment
The problem has to be with the threading part, but this works consistently fine when testing it locally. What can be happening?
asdf
is not an async function in your example.