Fix test leaking error_mode, fix equality check for VariableLookup

This is from #471, I'm just PR'ing it separately as I have other dependent changes for other branches.