From a3e85f52132642c91ff0edc52132c70f12436fd4 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 7 Mar 2019 17:47:23 +0800 Subject: [PATCH] fix: CSV relative path detection --- httprunner/__about__.py | 2 +- httprunner/exceptions.py | 3 +++ httprunner/loader.py | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/httprunner/__about__.py b/httprunner/__about__.py index 952b6b7c..5f7b3a5e 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.0.5' +__version__ = '2.0.6' __author__ = 'debugtalk' __author_email__ = 'mail@debugtalk.com' __license__ = 'Apache-2.0' diff --git a/httprunner/exceptions.py b/httprunner/exceptions.py index 3db701ee..787e864d 100644 --- a/httprunner/exceptions.py +++ b/httprunner/exceptions.py @@ -50,6 +50,9 @@ class VariableNotFound(NotFoundError): class EnvNotFound(NotFoundError): pass +class CSVNotFound(NotFoundError): + pass + class ApiNotFound(NotFoundError): pass diff --git a/httprunner/loader.py b/httprunner/loader.py index daec7c4b..ade04d6a 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -80,6 +80,15 @@ def load_csv_file(csv_file): ] """ + if not os.path.isabs(csv_file): + project_working_directory = tests_def_mapping["PWD"] or os.getcwd() + # make compatible with Windows/Linux + csv_file = os.path.join(project_working_directory, *csv_file.split("/")) + + if not os.path.isfile(csv_file): + # file path not exist + raise exceptions.CSVNotFound(csv_file) + csv_content_list = [] with io.open(csv_file, encoding='utf-8') as csvfile: