How to use the httprunner.exceptions.FileFormatError 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 / test_loader.py View on Github external
def test_load_yaml_file_file_format_error(self):
        yaml_tmp_file = "tests/data/tmp.yml"
        # create empty yaml file
        with open(yaml_tmp_file, 'w') as f:
            f.write("")

        with self.assertRaises(exceptions.FileFormatError):
            loader.load_yaml_file(yaml_tmp_file)

        os.remove(yaml_tmp_file)

        # create invalid format yaml file
        with open(yaml_tmp_file, 'w') as f:
            f.write("abc")

        with self.assertRaises(exceptions.FileFormatError):
            loader.load_yaml_file(yaml_tmp_file)

        os.remove(yaml_tmp_file)
github httprunner / httprunner / tests / test_loader / test_load.py View on Github external
def test_load_yaml_file_file_format_error(self):
        yaml_tmp_file = "tests/data/tmp.yml"
        # create empty yaml file
        with open(yaml_tmp_file, 'w') as f:
            f.write("")

        with self.assertRaises(exceptions.FileFormatError):
            load_test_file(yaml_tmp_file)

        os.remove(yaml_tmp_file)

        # create invalid format yaml file
        with open(yaml_tmp_file, 'w') as f:
            f.write("abc")

        with self.assertRaises(exceptions.FileFormatError):
            load_test_file(yaml_tmp_file)

        os.remove(yaml_tmp_file)
github httprunner / httprunner / httprunner / loader.py View on Github external
"""
    if not os.path.isfile(dot_env_path):
        return {}

    logger.info(f"Loading environment variables from {dot_env_path}")
    env_variables_mapping = {}

    with io.open(dot_env_path, "r", encoding="utf-8") as fp:
        for line in fp:
            # maxsplit=1
            if "=" in line:
                variable, value = line.split("=", 1)
            elif ":" in line:
                variable, value = line.split(":", 1)
            else:
                raise exceptions.FileFormatError(".env format error")

            env_variables_mapping[variable.strip()] = value.strip()

    utils.set_os_environ(env_variables_mapping)
    return env_variables_mapping
github httprunner / httprunner / httprunner / loader / load.py View on Github external
def _load_json_file(json_file):
    """ load json file and check file content format
    """
    with io.open(json_file, encoding="utf-8") as data_file:
        try:
            json_content = json.load(data_file)
        except json.JSONDecodeError:
            err_msg = f"JSONDecodeError: JSON file format error: {json_file}"
            logger.error(err_msg)
            raise exceptions.FileFormatError(err_msg)

        return json_content
github httprunner / httprunner / httprunner / exceptions.py View on Github external
"""


class MyBaseError(Exception):
    pass


class FileFormatError(MyBaseError):
    pass


class TestCaseFormatError(FileFormatError):
    pass


class TestSuiteFormatError(FileFormatError):
    pass


class ParamsError(MyBaseError):
    pass


class NotFoundError(MyBaseError):
    pass


class FileNotFound(FileNotFoundError, NotFoundError):
    pass


class FunctionNotFound(NotFoundError):
github httprunner / httprunner / httprunner / loader.py View on Github external
def _load_json_file(json_file: Text) -> Dict:
    """ load json file and check file content format
    """
    with io.open(json_file, encoding="utf-8") as data_file:
        try:
            json_content = json.load(data_file)
        except json.JSONDecodeError as ex:
            err_msg = f"JSONDecodeError:\nfile: {json_file}\nerror: {ex}"
            raise exceptions.FileFormatError(err_msg)

        return json_content
github httprunner / httprunner / httprunner / loader / check.py View on Github external
"""
    if not isinstance(data_structure, dict):
        return False

    if "apis" in data_structure:
        # maybe a group of api content
        apis = data_structure["apis"]
        if not isinstance(apis, list):
            return False

        for item in apis:
            is_testcase = False
            try:
                JsonSchemaChecker.validate_api_format(item)
                is_testcase = True
            except exceptions.FileFormatError:
                pass

            if not is_testcase:
                return False

        return True

    elif "testcases" in data_structure:
        # maybe a testsuite, containing a group of testcases
        testcases = data_structure["testcases"]
        if not isinstance(testcases, list):
            return False

        for item in testcases:
            is_testcase = False
            try:
github httprunner / httprunner / httprunner / loader / check.py View on Github external
def validate_testcase_format(content):
        """ check testcase format if valid
        """
        try:
            TestCase.parse_obj(content)
        except ValidationError as ex:
            logger.error(ex)
            raise exceptions.FileFormatError(ex)