This patch should fix both described issues from #2929, since they're based on the same problem. The parsing mechanism of optparse allows for partial matching of long options, as long as the common prefix is unique. This conflicts with the way we internally call "parse_args" for updating values after an AddOption().
On my side the full testsuite passed successfully. The additional test longopt.py breaks without the patch, but passes afterwards.