Make test main function return exit code

Return exit code rather than calling sys.exit directly.