From 7dc80c9c81cbde5f48ddfdfdbd218229479b4b7c Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 2 Jan 2020 15:29:37 +0800 Subject: [PATCH] fix: RefResolutionError on Windows platform --- docs/CHANGELOG.md | 6 ++++++ httprunner/loader/check.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e2a1294b..5de875a4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 2.5.1 (2020-01-02) + +**Fixed** + +- fix: RefResolutionError on Windows platform + ## 2.5.0 (2020-01-01) **Added** diff --git a/httprunner/loader/check.py b/httprunner/loader/check.py index b011be1a..ce8ec494 100644 --- a/httprunner/loader/check.py +++ b/httprunner/loader/check.py @@ -1,5 +1,6 @@ import json import os +import platform import jsonschema @@ -17,8 +18,14 @@ with open(api_schema_path) as f: api_schema = json.load(f) with open(common_schema_path) as f: + if platform.system() == "Windows": + absolute_base_path = 'file:///' + os.path.abspath(schemas_root_dir).replace("\\", "/") + '/' + else: + # Linux, Darwin + absolute_base_path = "file://" + os.path.abspath(schemas_root_dir) + "/" + common_schema = json.load(f) - resolver = jsonschema.RefResolver("file://{}/".format(os.path.abspath(schemas_root_dir)), common_schema) + resolver = jsonschema.RefResolver(absolute_base_path, common_schema) with open(testcase_schema_v1_path) as f: testcase_schema_v1 = json.load(f)