upgrade to 0.9.7: support .env file

This commit is contained in:
debugtalk
2018-02-27 16:36:05 +08:00
parent 98c72c7890
commit 41c979e897
4 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@ logs/%
.coverage
locustfile.py
site/
.env

View File

@@ -1,7 +1,7 @@
__title__ = 'HttpRunner'
__description__ = 'HTTP test runner, not just about api test and load test.'
__url__ = 'https://github.com/HttpRunner/HttpRunner'
__version__ = '0.9.6a2'
__version__ = '0.9.7'
__author__ = 'debugtalk'
__author_email__ = 'mail@debugtalk.com'
__license__ = 'MIT'

View File

@@ -7,7 +7,8 @@ import unittest
from httprunner import logger
from httprunner.__about__ import __version__
from httprunner.task import HttpRunner
from httprunner.utils import create_scaffold, print_output, string_type
from httprunner.utils import (create_scaffold, load_dot_env_file, print_output,
string_type)
def main_hrun():
@@ -30,6 +31,9 @@ def main_hrun():
parser.add_argument(
'--log-level', default='INFO',
help="Specify logging level, default is INFO.")
parser.add_argument(
'--dot-env-path',
help="Specify .env file path, which is useful for keeping production credentials.")
parser.add_argument(
'--failfast', action='store_true', default=False,
help="Stop the test run on the first error or failure.")
@@ -44,6 +48,10 @@ def main_hrun():
logger.color_print("{}".format(__version__), "GREEN")
exit(0)
dot_env_path = args.dot_env_path or os.path.join(os.getcwd(), ".env")
if dot_env_path:
load_dot_env_file(dot_env_path)
project_name = args.startproject
if project_name:
project_path = os.path.join(os.getcwd(), project_name)

View File

@@ -2,6 +2,7 @@ import hashlib
import hmac
import imp
import importlib
import io
import os.path
import random
import re
@@ -390,3 +391,16 @@ def create_scaffold(project_path):
msg += create_path(p[0], p[1])
logger.color_print(msg, "BLUE")
def load_dot_env_file(path):
""" load .env file and set to os.environ
"""
if not os.path.isfile(path):
return
logger.log_info("Loading environment variables from {}".format(path))
with io.open(path, 'r', encoding='utf-8') as fp:
for line in fp:
variable, value = line.split("=")
os.environ[variable] = value
logger.log_debug("Loaded variable: {}".format(variable))