How to use the httprunner.exceptions.ParamsError function in httprunner

To help you get started, we’ve selected a few httprunner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github httprunner / httprunner / tests / View on Github external
def test_eval_content_variables_search_upward(self):
        testcase_parser = testcase.TestcaseParser()

        with self.assertRaises(exceptions.ParamsError):

        testcase_parser.file_path = "tests/data/demo_testset_hardcode.yml"
        content = testcase_parser._eval_content_variables("/api/$SECRET_KEY")
        self.assertEqual(content, "/api/DebugTalk")
github httprunner / httprunner / httprunner / View on Github external
return self.functions[item_name]

                # check if builtin functions
                item_func = eval(item_name)
                if callable(item_func):
                    # is builtin function
                    return item_func
            except (NameError, TypeError):
                # is not builtin function, continue to search
        elif item_type == "variable":
            if item_name in self.variables:
                return self.variables[item_name]
            raise exceptions.ParamsError("bind item should only be function or variable.")

            assert self.file_path is not None
            return utils.search_conf_item(self.file_path, item_type, item_name)
        except (AssertionError, exceptions.FunctionNotFound):
            raise exceptions.ParamsError(
                "{} is not defined in bind {}s!".format(item_name, item_type))
github httprunner / httprunner / httprunner / v3 / View on Github external
def __getattr__(self, key):
            if key == "json":
                value = self.resp_obj.json()
            elif key == "cookies":
                value = self.resp_obj.cookies.get_dict()
                value = getattr(self.resp_obj, key)

            self.__dict__[key] = value
            return value
        except AttributeError:
            err_msg = f"ResponseObject does not have attribute: {key}"
            raise ParamsError(err_msg)
github httprunner / httprunner / httprunner / View on Github external
def extract_field(self, field):
        """ extract value from requests.Response.
        if not isinstance(field, basestring):
            err_msg = u"Invalid extractor! => {}\n".format(field)
            raise exceptions.ParamsError(err_msg)

        msg = "extract: {}".format(field)

        if text_extractor_regexp_compile.match(field):
            value = self._extract_field_with_regex(field)
            value = self._extract_field_with_delimiter(field)

        if is_py2 and isinstance(value, unicode):
            value = value.encode("utf-8")

        msg += "\t=> {}".format(value)

        return value
github httprunner / httprunner / httprunner / View on Github external
                return cookies[sub_query]
            except KeyError:
                err_msg = u"Failed to extract cookie! => {}\n".format(field)
                err_msg += u"response cookies: {}\n".format(cookies)
                raise exceptions.ExtractFailure(err_msg)

        # elapsed
        elif top_query == "elapsed":
            available_attributes = u"available attributes: days, seconds, microseconds, total_seconds"
            if not sub_query:
                err_msg = u"elapsed is datetime.timedelta instance, attribute should also be specified!\n"
                err_msg += available_attributes
                raise exceptions.ParamsError(err_msg)
            elif sub_query in ["days", "seconds", "microseconds"]:
                return getattr(self.elapsed, sub_query)
            elif sub_query == "total_seconds":
                return self.elapsed.total_seconds()
                err_msg = "{} is not valid datetime.timedelta attribute.\n".format(sub_query)
                err_msg += available_attributes
                raise exceptions.ParamsError(err_msg)

        # headers
        elif top_query == "headers":
            headers = self.headers
            if not sub_query:
                # extract headers
                return headers
github httprunner / httprunner / httprunner / View on Github external
def convert_relative_project_root_dir(abs_path: Text) -> Text:
    """ convert absolute path to relative path, based on project_meta.RootDir

        abs_path: absolute path

    Returns: relative path based on project_meta.RootDir

    _project_meta = load_project_meta(abs_path)
    if not abs_path.startswith(_project_meta.RootDir):
        raise exceptions.ParamsError(
            f"failed to convert absolute path to relative path based on project_meta.RootDir\n"
            f"abs_path: {abs_path}\n"
            f"project_meta.RootDir: {_project_meta.RootDir}"

    return abs_path[len(_project_meta.RootDir) + 1 :]
github httprunner / httprunner / httprunner / View on Github external
testcase_parametered_variables_list = self._get_parametered_variables(
                    teststep_dict.get("variables", []),
                    teststep_dict.get("parameters", [])
                for testcase_variables in testcase_parametered_variables_list:
                    teststep_dict["variables"] = testcase_variables

                    # eval teststep name with bind variables
                    variables = utils.override_variables_binds(
                        testcase_name = self.testcase_parser.eval_content_with_bindings(teststep_dict["name"])
                    except (AssertionError, exceptions.ParamsError):
                        logger.log_warning("failed to eval teststep name: {}".format(teststep_dict["name"]))
                        testcase_name = teststep_dict["name"]
                    self.test_runner_list.append((test_runner, variables))

                    self._add_test_to_suite(testcase_name, test_runner, teststep_dict)
github httprunner / httprunner / httprunner / View on Github external
def __run_step(self, step: TStep) -> Dict:
        """run teststep, teststep maybe a request or referenced testcase""""run step begin: {} >>>>>>")

        if step.request:
            step_data = self.__run_step_request(step)
        elif step.testcase:
            step_data = self.__run_step_testcase(step)
            raise ParamsError(
                f"teststep is neither a request nor a referenced testcase: {step.dict()}"

        self.__step_datas.append(step_data)"run step end: {} <<<<<<\n")
        return step_data.export_vars
github httprunner / httprunner / httprunner / View on Github external
return utils.query_json(attributes, sub_query)
                # content = "attributes.new_attribute_not_exist"
                err_msg = u"Failed to extract cumstom set attribute from teardown hooks! => {}\n".format(field)
                err_msg += u"response set attributes: {}\n".format(attributes)
                raise exceptions.TeardownHooksFailure(err_msg)

        # others
            err_msg = u"Failed to extract attribute from response! => {}\n".format(field)
            err_msg += u"available response attributes: status_code, cookies, elapsed, headers, content, text, json, encoding, ok, reason, url.\n\n"
            err_msg += u"If you want to set attribute in teardown_hooks, take the following example as reference:\n"
            err_msg += u"response.new_attribute = 'new_attribute_value'\n"
            raise exceptions.ParamsError(err_msg)