The problem is that when the worker returns the scope of “with” statement ends making the object take its real value, the solution is to use “yield”.
@pytest.fixture()
def mocked_worker():
with patch('test.test_module.os.getcwd', return_value="Testing"):
result = Worker()
yield result