diff --git a/docs/development.md b/docs/development.md index 5bb0a4f9..a19dd02e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,9 +1,9 @@ ## Development -To develop or debug `HttpRunner`, you can install relevant requirements and use `main-hrun.py` or `main-locust.py` as entrances. +To develop or debug `HttpRunner`, you can install relevant requirements and use `httprunner/cli.py` as entrances. ```bash $ python setup.py install -$ python main-hrun -h -$ python main-locust -h +$ python httprunner/cli.py hrun -h +$ python httprunner/cli.py locust -h ``` diff --git a/httprunner/cli.py b/httprunner/cli.py index f8fdece1..b3f0c796 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -5,15 +5,14 @@ import sys import unittest from collections import OrderedDict +from httprunner import __version__ as hrun_version +from httprunner import logger +from httprunner.exception import TestcaseNotFound +from httprunner.task import Result, TaskSuite +from httprunner.utils import create_scaffold, print_output, string_type from pyunitreport import __version__ as pyu_version from pyunitreport import HTMLTestRunner -from . import __version__ as hrun_version -from . import logger -from .exception import TestcaseNotFound -from .task import Result, TaskSuite -from .utils import create_scaffold, print_output, string_type - def run_suite_path(path, mapping=None, runner=None): """ run suite with YAML/JSON file path @@ -144,3 +143,12 @@ def main_locust(): locusts.run_locusts_on_cpu_cores(sys.argv, cpu_cores_num_value) else: locusts.main() + + +if __name__ == '__main__': + cmd = sys.argv.pop(1) + + if cmd == "hrun": + main_hrun() + elif cmd == "locust": + main_locust() diff --git a/httprunner/client.py b/httprunner/client.py index 6d65d2c5..fb3161ac 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -4,13 +4,12 @@ import time import requests import urllib3 +from httprunner import logger +from httprunner.exception import ParamsError from requests import Request, Response from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema, RequestException) -from . import logger -from .exception import ParamsError - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) absolute_http_url_regexp = re.compile(r"^https?://", re.I) diff --git a/httprunner/locusts.py b/httprunner/locusts.py index 9bcdc459..66a16ce3 100644 --- a/httprunner/locusts.py +++ b/httprunner/locusts.py @@ -3,10 +3,10 @@ import multiprocessing import os import sys -from locust.main import main +from httprunner.logger import color_print +from httprunner.testcase import load_test_file -from .logger import color_print -from .testcase import load_test_file +from locust.main import main def parse_locustfile(file_path): diff --git a/httprunner/response.py b/httprunner/response.py index 5f006d12..3813a951 100644 --- a/httprunner/response.py +++ b/httprunner/response.py @@ -1,10 +1,9 @@ import re from collections import OrderedDict +from httprunner import exception, logger, testcase, utils from requests.structures import CaseInsensitiveDict -from . import exception, logger, testcase, utils - text_extractor_regexp_compile = re.compile(r".*\(.*\).*") diff --git a/httprunner/runner.py b/httprunner/runner.py index 4a777577..63e3d284 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -1,8 +1,8 @@ from unittest.case import SkipTest -from . import exception, logger, response, testcase, utils -from .client import HttpSession -from .context import Context +from httprunner import exception, logger, response, testcase, utils +from httprunner.client import HttpSession +from httprunner.context import Context class Runner(object): diff --git a/httprunner/task.py b/httprunner/task.py index 48fabdde..b3db2be6 100644 --- a/httprunner/task.py +++ b/httprunner/task.py @@ -1,6 +1,6 @@ import unittest -from . import exception, logger, runner, testcase, utils +from httprunner import exception, logger, runner, testcase, utils class ApiTestCase(unittest.TestCase): diff --git a/httprunner/testcase.py b/httprunner/testcase.py index 7fd441a7..5cfcd22e 100644 --- a/httprunner/testcase.py +++ b/httprunner/testcase.py @@ -8,8 +8,7 @@ import re from collections import OrderedDict import yaml - -from . import exception, logger, utils +from httprunner import exception, logger, utils variable_regexp = r"\$([\w_]+)" function_regexp = r"\$\{([\w_]+\([\$\w_ =,]*\))\}" diff --git a/httprunner/utils.py b/httprunner/utils.py index 7abc2e79..ae079935 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -9,10 +9,9 @@ import string import types from collections import OrderedDict +from httprunner import exception, logger from requests.structures import CaseInsensitiveDict -from . import exception, logger - try: string_type = basestring long_type = long diff --git a/main-hrun.py b/main-hrun.py deleted file mode 100644 index 2611ba9b..00000000 --- a/main-hrun.py +++ /dev/null @@ -1,5 +0,0 @@ -""" used for debugging -""" - -from httprunner.cli import main_hrun -main_hrun() diff --git a/main-locust.py b/main-locust.py deleted file mode 100644 index ea79ce4d..00000000 --- a/main-locust.py +++ /dev/null @@ -1,5 +0,0 @@ -""" used for debugging -""" - -from httprunner.cli import main_locust -main_locust()