bugfix: strip environment value

This commit is contained in:
httprunner
2018-06-11 20:00:37 +08:00
parent 2b40399d05
commit a202fc0866
3 changed files with 4 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
__title__ = 'HttpRunner' __title__ = 'HttpRunner'
__description__ = 'One-stop solution for HTTP(S) testing.' __description__ = 'One-stop solution for HTTP(S) testing.'
__url__ = 'https://github.com/HttpRunner/HttpRunner' __url__ = 'https://github.com/HttpRunner/HttpRunner'
__version__ = '1.4.5' __version__ = '1.4.6'
__author__ = 'debugtalk' __author__ = 'debugtalk'
__author_email__ = 'mail@debugtalk.com' __author_email__ = 'mail@debugtalk.com'
__license__ = 'MIT' __license__ = 'MIT'

View File

@@ -513,7 +513,8 @@ def load_dot_env_file(path):
with io.open(path, 'r', encoding='utf-8') as fp: with io.open(path, 'r', encoding='utf-8') as fp:
for line in fp: for line in fp:
variable, value = line.split("=") variable, value = line.split("=")
os.environ[variable] = value variable = variable.strip()
os.environ[variable] = value.strip()
logger.log_debug("Loaded variable: {}".format(variable)) logger.log_debug("Loaded variable: {}".format(variable))
def validate_json_file(file_list): def validate_json_file(file_list):

View File

@@ -158,6 +158,7 @@ class TestHttpRunner(ApiServerUnittest):
self.assertNotIn("PROJECT_KEY", os.environ) self.assertNotIn("PROJECT_KEY", os.environ)
HttpRunner(dot_env_path="tests/data/test.env").run(self.testset_path) HttpRunner(dot_env_path="tests/data/test.env").run(self.testset_path)
self.assertIn("PROJECT_KEY", os.environ) self.assertIn("PROJECT_KEY", os.environ)
self.assertEqual(os.environ["UserName"], "debugtalk")
def test_load_env_path_not_exist(self): def test_load_env_path_not_exist(self):
with self.assertRaises(FileNotFoundError): with self.assertRaises(FileNotFoundError):