Fixing cookie commands. Include port of java cookie regression tests.

Fixes issue 5321.
Added pytestopts= option for passing arguments to the python test framework
Catch only the exception type(s) we expect.
Cleaned up test.  Still intermittently fails.