mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
upgrade to 0.9.7: support .env file
This commit is contained in:
@@ -12,3 +12,4 @@ logs/%
|
|||||||
.coverage
|
.coverage
|
||||||
locustfile.py
|
locustfile.py
|
||||||
site/
|
site/
|
||||||
|
.env
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
__title__ = 'HttpRunner'
|
__title__ = 'HttpRunner'
|
||||||
__description__ = 'HTTP test runner, not just about api test and load test.'
|
__description__ = 'HTTP test runner, not just about api test and load test.'
|
||||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||||
__version__ = '0.9.6a2'
|
__version__ = '0.9.7'
|
||||||
__author__ = 'debugtalk'
|
__author__ = 'debugtalk'
|
||||||
__author_email__ = 'mail@debugtalk.com'
|
__author_email__ = 'mail@debugtalk.com'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|||||||
+9
-1
@@ -7,7 +7,8 @@ import unittest
|
|||||||
from httprunner import logger
|
from httprunner import logger
|
||||||
from httprunner.__about__ import __version__
|
from httprunner.__about__ import __version__
|
||||||
from httprunner.task import HttpRunner
|
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():
|
def main_hrun():
|
||||||
@@ -30,6 +31,9 @@ def main_hrun():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--log-level', default='INFO',
|
'--log-level', default='INFO',
|
||||||
help="Specify logging level, default is 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(
|
parser.add_argument(
|
||||||
'--failfast', action='store_true', default=False,
|
'--failfast', action='store_true', default=False,
|
||||||
help="Stop the test run on the first error or failure.")
|
help="Stop the test run on the first error or failure.")
|
||||||
@@ -44,6 +48,10 @@ def main_hrun():
|
|||||||
logger.color_print("{}".format(__version__), "GREEN")
|
logger.color_print("{}".format(__version__), "GREEN")
|
||||||
exit(0)
|
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
|
project_name = args.startproject
|
||||||
if project_name:
|
if project_name:
|
||||||
project_path = os.path.join(os.getcwd(), project_name)
|
project_path = os.path.join(os.getcwd(), project_name)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
import imp
|
import imp
|
||||||
import importlib
|
import importlib
|
||||||
|
import io
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@@ -390,3 +391,16 @@ def create_scaffold(project_path):
|
|||||||
msg += create_path(p[0], p[1])
|
msg += create_path(p[0], p[1])
|
||||||
|
|
||||||
logger.color_print(msg, "BLUE")
|
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))
|
||||||
|
|||||||
Reference in New Issue
Block a user