tests: Factor out common code in qapi output tests