def var_mock(request, q_var_name, **kwargs):
 _patch = patch(q_var_name, **kwargs)
 request.addfinalizer(_patch.stop)
 return _patch.start()

def var_mock ( request , q_var_name , ** kwargs ) : _patch = patch ( q_var_name , ** kwargs ) request . addfinalizer ( _patch . stop ) return _patch . start ( )
return a mock patching the variable with qualified name *q_var_name* .