From b6878bd9d90691818cc2757d2863adb9e9c0b11d Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 30 Jun 2019 20:53:42 +0800 Subject: [PATCH] fix: yaml FullLoader AttributeError when PyYAML version < 5.1 --- CHANGELOG.md | 6 ++++++ httprunner/__about__.py | 2 +- httprunner/loader.py | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5905db50..40e9122b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 2.2.3 + +**Bugfixes** + +- fix yaml FullLoader AttributeError when PyYAML version < 5.1 + ## 2.2.2 (2019-06-26) **Features** diff --git a/httprunner/__about__.py b/httprunner/__about__.py index 2c14eaef..d3f8c825 100644 --- a/httprunner/__about__.py +++ b/httprunner/__about__.py @@ -1,7 +1,7 @@ __title__ = 'HttpRunner' __description__ = 'One-stop solution for HTTP(S) testing.' __url__ = 'https://github.com/HttpRunner/HttpRunner' -__version__ = '2.2.2' +__version__ = '2.2.3' __author__ = 'debugtalk' __author_email__ = 'mail@debugtalk.com' __license__ = 'Apache-2.0' diff --git a/httprunner/loader.py b/httprunner/loader.py index bd346d42..0bf93417 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -10,6 +10,13 @@ import sys import yaml from httprunner import built_in, exceptions, logger, parser, utils, validator +try: + # PyYAML version >= 5.1 + # ref: https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation + yaml.warnings({'YAMLLoadWarning': False}) +except AttributeError: + pass + ############################################################################### ## file loader ############################################################################### @@ -35,7 +42,7 @@ def load_yaml_file(yaml_file): """ load yaml file and check file content format """ with io.open(yaml_file, 'r', encoding='utf-8') as stream: - yaml_content = yaml.load(stream, Loader=yaml.FullLoader) + yaml_content = yaml.load(stream) _check_format(yaml_file, yaml_content) return yaml_content