mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +08:00
fix:thrift/sql改为可选
This commit is contained in:
@@ -1,21 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import time
|
||||
from typing import Text
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from httprunner import utils
|
||||
from httprunner.exceptions import SqlMethodNotSupport
|
||||
from httprunner.exceptions import ValidationFailure
|
||||
from httprunner.models import IStep, StepResult, TStep
|
||||
from httprunner.models import TSqlRequest, SqlMethodEnum
|
||||
from httprunner.models import SqlMethodEnum, TSqlRequest
|
||||
from httprunner.response import SqlResponseObject
|
||||
from httprunner.runner import HttpRunner
|
||||
from httprunner.step_request import (
|
||||
call_hooks,
|
||||
StepRequestExtraction,
|
||||
StepRequestValidation,
|
||||
)
|
||||
from httprunner.exceptions import SqlMethodNotSupport
|
||||
from httprunner.step_request import (StepRequestExtraction, StepRequestValidation, call_hooks)
|
||||
|
||||
try:
|
||||
import sqlalchemy
|
||||
import pymysql
|
||||
|
||||
SQL_READY = True
|
||||
except ModuleNotFoundError:
|
||||
SQL_READY = False
|
||||
|
||||
|
||||
def ensure_sql_ready():
|
||||
if SQL_READY:
|
||||
return
|
||||
|
||||
msg = """
|
||||
uploader extension dependencies uninstalled, install first and try again.
|
||||
install with pip:
|
||||
$ pip install sqlalchemy pymysql
|
||||
|
||||
or you can install httprunner with optional upload dependencies:
|
||||
$ pip install "httprunner[sql]"
|
||||
"""
|
||||
logger.error(msg)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult:
|
||||
@@ -51,8 +71,8 @@ def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult:
|
||||
)
|
||||
|
||||
if not runner.db_engine:
|
||||
ensure_sql_ready()
|
||||
from httprunner.database.engine import DBEngine
|
||||
|
||||
runner.db_engine = DBEngine(
|
||||
f'mysql+pymysql://{parsed_request_dict["db_config"]["user"]}:'
|
||||
f'{parsed_request_dict["db_config"]["password"]}@{parsed_request_dict["db_config"]["ip"]}:'
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import platform
|
||||
import sys
|
||||
import time
|
||||
from typing import Text, Union
|
||||
|
||||
@@ -22,6 +24,31 @@ from httprunner.step_request import (
|
||||
call_hooks,
|
||||
)
|
||||
|
||||
try:
|
||||
import thriftpy2
|
||||
from thrift.Thrift import TType
|
||||
|
||||
THRIFT_READY = True
|
||||
except ModuleNotFoundError:
|
||||
THRIFT_READY = False
|
||||
|
||||
|
||||
def ensure_thrift_ready():
|
||||
assert platform.system() != "Windows", "Sorry,thrift not support Windows for now"
|
||||
if THRIFT_READY:
|
||||
return
|
||||
|
||||
msg = """
|
||||
uploader extension dependencies uninstalled, install first and try again.
|
||||
install with pip:
|
||||
$ pip install cython thriftpy2 thrift
|
||||
|
||||
or you can install httprunner with optional upload dependencies:
|
||||
$ pip install "httprunner[thrift]"
|
||||
"""
|
||||
logger.error(msg)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
||||
"""run teststep:thrift request"""
|
||||
@@ -76,8 +103,8 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
||||
if not runner.thrift_client:
|
||||
runner.thrift_client = parsed_request_dict["thrift_client"]
|
||||
if not runner.thrift_client:
|
||||
ensure_thrift_ready()
|
||||
from httprunner.thrift.thrift_client import ThriftClient
|
||||
|
||||
runner.thrift_client = ThriftClient(
|
||||
thrift_file=parsed_request_dict["idl_path"],
|
||||
service_name=parsed_request_dict["service_name"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
import platform
|
||||
|
||||
import enum
|
||||
import json
|
||||
|
||||
@@ -84,7 +84,6 @@ class ThriftClient(object):
|
||||
self.timeout = timeout
|
||||
self.proto_type = proto_type
|
||||
self.trans_type = trans_type
|
||||
assert platform.system() != "Windows", "thrift not support Windows for now"
|
||||
try:
|
||||
logger.debug(
|
||||
"init thrift module: thrift_file=%s, module_name=%s",
|
||||
|
||||
Reference in New Issue
Block a user