call load_dot_env_file when initializing HttpRunner

This commit is contained in:
debugtalk
2018-05-09 17:16:20 +08:00
parent 9c26dba415
commit a414fe56d5
6 changed files with 30 additions and 10 deletions

3
tests/data/test.env Normal file
View File

@@ -0,0 +1,3 @@
UserName=debugtalk
Password=123456
PROJECT_KEY=ABCDEFGH

View File

@@ -2,6 +2,7 @@ import os
import shutil
from httprunner import HttpRunner
from httprunner.exception import FileNotFoundError
from tests.base import ApiServerUnittest
@@ -152,3 +153,12 @@ class TestHttpRunner(ApiServerUnittest):
summary = runner.summary
self.assertTrue(summary["success"])
self.assertEqual(summary["stat"]["testsRun"], 8)
def test_load_env_path(self):
self.assertNotIn("PROJECT_KEY", os.environ)
HttpRunner(dot_env_path="tests/data/test.env").run(self.testset_path)
self.assertIn("PROJECT_KEY", os.environ)
def test_load_env_path_not_exist(self):
with self.assertRaises(FileNotFoundError):
HttpRunner(dot_env_path="not_exist.env").run(self.testset_path)