def replace_error_method(arg_parser):
    def error_method(self, message):
        raise argparse.ArgumentError(None, message)

    def exit_method(self, status, message):
        self._exit_method_called = True

    arg_parser._exit_method_called = False
    arg_parser.error = types.MethodType(error_method, arg_parser)
    arg_parser.exit = types.MethodType(exit_method, arg_parser)

    return arg_parser
Swap out arg_parser's error(..) method so that instead of calling
dataset/ETHPy150Open bw2/ConfigArgParse/tests/test_configargparse.py/replace_error_method