mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 08:49:37 +08:00
load built_in when loading project tests
This commit is contained in:
@@ -6,10 +6,9 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from httprunner import exceptions, logger, parser, validator
|
from httprunner import built_in, exceptions, logger, parser, validator
|
||||||
from httprunner.compat import OrderedDict
|
from httprunner.compat import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
project_mapping = {
|
project_mapping = {
|
||||||
"debugtalk": {},
|
"debugtalk": {},
|
||||||
"env": {},
|
"env": {},
|
||||||
@@ -297,7 +296,7 @@ def load_python_module(module):
|
|||||||
|
|
||||||
|
|
||||||
def load_debugtalk_module(start_path=None):
|
def load_debugtalk_module(start_path=None):
|
||||||
""" load debugtalk.py module.
|
""" load built_in module and project debugtalk.py module.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
start_path (str, optional): start locating path, maybe file path or directory path.
|
start_path (str, optional): start locating path, maybe file path or directory path.
|
||||||
@@ -312,22 +311,27 @@ def load_debugtalk_module(start_path=None):
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# load built_in module
|
||||||
|
built_in_module = load_python_module(built_in)
|
||||||
|
|
||||||
start_path = start_path or os.getcwd()
|
start_path = start_path or os.getcwd()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module_path = locate_file(start_path, "debugtalk.py")
|
module_path = locate_file(start_path, "debugtalk.py")
|
||||||
module_name = convert_module_name(module_path)
|
module_name = convert_module_name(module_path)
|
||||||
except exceptions.FileNotFound:
|
except exceptions.FileNotFound:
|
||||||
return {
|
return built_in_module
|
||||||
"variables": {},
|
|
||||||
"functions": {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
# load debugtalk.py module
|
||||||
imported_module = importlib.import_module(module_name)
|
imported_module = importlib.import_module(module_name)
|
||||||
loaded_module = load_python_module(imported_module)
|
debugtalk_module = load_python_module(imported_module)
|
||||||
|
|
||||||
project_mapping["debugtalk"] = loaded_module
|
# override built_in module with debugtalk.py module
|
||||||
return loaded_module
|
debugtalk_module["variables"].update(built_in_module["variables"])
|
||||||
|
debugtalk_module["functions"].update(built_in_module["functions"])
|
||||||
|
|
||||||
|
project_mapping["debugtalk"] = debugtalk_module
|
||||||
|
return debugtalk_module
|
||||||
|
|
||||||
|
|
||||||
def get_module_item(module_mapping, item_type, item_name):
|
def get_module_item(module_mapping, item_type, item_name):
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class TestFileLoader(unittest.TestCase):
|
|||||||
"tests/debugtalk.py"
|
"tests/debugtalk.py"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestModuleLoader(unittest.TestCase):
|
class TestModuleLoader(unittest.TestCase):
|
||||||
|
|
||||||
def test_filter_module_functions(self):
|
def test_filter_module_functions(self):
|
||||||
@@ -180,8 +181,10 @@ class TestModuleLoader(unittest.TestCase):
|
|||||||
|
|
||||||
def test_load_debugtalk_module(self):
|
def test_load_debugtalk_module(self):
|
||||||
imported_module_items = loader.load_debugtalk_module()
|
imported_module_items = loader.load_debugtalk_module()
|
||||||
self.assertEqual(imported_module_items["functions"], {})
|
self.assertIn("basestring", imported_module_items["variables"])
|
||||||
self.assertEqual(imported_module_items["variables"], {})
|
self.assertIn("equals", imported_module_items["functions"])
|
||||||
|
self.assertNotIn("SECRET_KEY", imported_module_items["variables"])
|
||||||
|
self.assertNotIn("alter_response", imported_module_items["functions"])
|
||||||
|
|
||||||
imported_module_items = loader.load_debugtalk_module("tests")
|
imported_module_items = loader.load_debugtalk_module("tests")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user