tests: factorize has_opt handling

Change-Id: I7d5551af250c1e24177e0e7eed0bd622bb06ca29
Merge "tests: factorize has_opt handling"