mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
fix #189: remove file path dependency
This commit is contained in:
@@ -52,7 +52,7 @@ class HttpRunner(object):
|
||||
{
|
||||
"config": {
|
||||
"name": "desc1",
|
||||
"path": "",
|
||||
"path": "", # optional
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
},
|
||||
@@ -79,15 +79,15 @@ class HttpRunner(object):
|
||||
for testcase in path_or_testcases:
|
||||
try:
|
||||
test_path = os.path.dirname(testcase["config"]["path"])
|
||||
loader.load_project_tests(test_path)
|
||||
except KeyError:
|
||||
pass
|
||||
test_path = os.getcwd()
|
||||
loader.load_project_tests(test_path)
|
||||
else:
|
||||
try:
|
||||
test_path = os.path.dirname(path_or_testcases["config"]["path"])
|
||||
loader.load_project_tests(test_path)
|
||||
except KeyError:
|
||||
pass
|
||||
test_path = os.getcwd()
|
||||
loader.load_project_tests(test_path)
|
||||
|
||||
testcases = path_or_testcases
|
||||
else:
|
||||
|
||||
@@ -424,9 +424,7 @@ def _load_test_file(file_path):
|
||||
|
||||
"""
|
||||
testcase = {
|
||||
"config": {
|
||||
"path": file_path
|
||||
},
|
||||
"config": {},
|
||||
"teststeps": []
|
||||
}
|
||||
|
||||
@@ -856,9 +854,7 @@ def load_test_folder(test_folder_path):
|
||||
# TODO: add JSON schema validation
|
||||
|
||||
testcase = {
|
||||
"config": {
|
||||
"path": test_file_path
|
||||
},
|
||||
"config": {},
|
||||
"teststeps": []
|
||||
}
|
||||
for item in items:
|
||||
@@ -914,12 +910,12 @@ def load_project_tests(test_path):
|
||||
"""
|
||||
reset_loader()
|
||||
locate_pwd(test_path)
|
||||
load_builtin_module()
|
||||
load_api_folder(os.path.join(project_working_directory, "api"))
|
||||
load_test_folder(os.path.join(project_working_directory, "suite"))
|
||||
# load .env
|
||||
load_dot_env_file()
|
||||
load_builtin_module()
|
||||
load_debugtalk_module()
|
||||
load_api_folder(os.path.join(project_working_directory, "api"))
|
||||
# TODO: replace suite with testcases
|
||||
load_test_folder(os.path.join(project_working_directory, "suite"))
|
||||
|
||||
|
||||
def load_testcases(path):
|
||||
|
||||
@@ -45,7 +45,6 @@ class Runner(object):
|
||||
testcase:
|
||||
{
|
||||
"name": "testcase description",
|
||||
"path": "tests/data/demo_testset_variables.yml",
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"base_url": "http://127.0.0.1:5000",
|
||||
|
||||
@@ -14,7 +14,6 @@ def is_testcase(data_structure):
|
||||
{
|
||||
"config": {
|
||||
"name": "desc1",
|
||||
"path": "",
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
},
|
||||
|
||||
@@ -21,7 +21,6 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.testcase = {
|
||||
'name': 'testset description',
|
||||
'config': {
|
||||
'path': 'docs/data/demo-quickstart-2.yml',
|
||||
'name': 'testset description',
|
||||
'request': {
|
||||
'base_url': '',
|
||||
@@ -181,7 +180,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
{
|
||||
"config": {
|
||||
"name": "test teardown hooks",
|
||||
'path': 'tests/httpbin/hooks.yml',
|
||||
"path": "tests/httpbin/hooks.yml"
|
||||
},
|
||||
"teststeps": [
|
||||
{
|
||||
@@ -217,7 +216,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
"config": {
|
||||
'path': 'tests/httpbin/hooks.yml',
|
||||
"path": "tests/httpbin/hooks.yml"
|
||||
},
|
||||
"teststeps": [
|
||||
{
|
||||
@@ -246,9 +245,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
testcases = [
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
"config": {
|
||||
'path': 'tests/httpbin/hooks.yml',
|
||||
},
|
||||
"config": {},
|
||||
"teststeps": [
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
|
||||
@@ -246,7 +246,6 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
def test_load_test_file_testcase(self):
|
||||
testcase = loader._load_test_file("tests/testcases/smoketest.yml")
|
||||
self.assertEqual(testcase["config"]["name"], "smoketest")
|
||||
self.assertEqual(testcase["config"]["path"], "tests/testcases/smoketest.yml")
|
||||
self.assertIn("device_sn", testcase["config"]["variables"][0])
|
||||
self.assertEqual(len(testcase["teststeps"]), 8)
|
||||
self.assertEqual(testcase["teststeps"][0]["name"], "get token")
|
||||
@@ -365,8 +364,6 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
os.getcwd(), 'tests/data/demo_testset_hardcode.json')
|
||||
testset_list = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list), 1)
|
||||
self.assertIn("path", testset_list[0]["config"])
|
||||
self.assertEqual(testset_list[0]["config"]["path"], path)
|
||||
self.assertEqual(len(testset_list[0]["teststeps"]), 3)
|
||||
testsets_list.extend(testset_list)
|
||||
|
||||
@@ -374,8 +371,6 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
path = 'tests/data/demo_testset_hardcode.yml'
|
||||
testset_list = loader.load_testcases(path)
|
||||
self.assertEqual(len(testset_list), 1)
|
||||
self.assertIn("path", testset_list[0]["config"])
|
||||
self.assertIn(path, testset_list[0]["config"]["path"])
|
||||
self.assertEqual(len(testset_list[0]["teststeps"]), 3)
|
||||
testsets_list.extend(testset_list)
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ class TestRunner(ApiServerUnittest):
|
||||
start_time = time.time()
|
||||
|
||||
config_dict = {
|
||||
"path": os.path.join(os.getcwd(), __file__),
|
||||
"name": "basic test with httpbin",
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"],
|
||||
@@ -130,7 +129,6 @@ class TestRunner(ApiServerUnittest):
|
||||
|
||||
def test_run_testset_with_hooks_modify_request(self):
|
||||
config_dict = {
|
||||
"path": os.path.join(os.getcwd(), __file__),
|
||||
"name": "basic test with httpbin",
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"],
|
||||
@@ -185,9 +183,7 @@ class TestRunner(ApiServerUnittest):
|
||||
],
|
||||
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"]
|
||||
}
|
||||
config_dict = {
|
||||
"path": os.path.join(os.getcwd(), __file__)
|
||||
}
|
||||
config_dict = {}
|
||||
self.test_runner.init_config(config_dict, "testcase")
|
||||
|
||||
start_time = time.time()
|
||||
@@ -218,9 +214,7 @@ class TestRunner(ApiServerUnittest):
|
||||
],
|
||||
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"]
|
||||
}
|
||||
config_dict = {
|
||||
"path": os.path.join(os.getcwd(), __file__)
|
||||
}
|
||||
config_dict = {}
|
||||
self.test_runner.init_config(config_dict, "testcase")
|
||||
|
||||
start_time = time.time()
|
||||
@@ -246,9 +240,7 @@ class TestRunner(ApiServerUnittest):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/test_bugfix.yml')
|
||||
testcases = loader.load_file(testcase_file_path)
|
||||
config_dict = {
|
||||
"path": testcase_file_path
|
||||
}
|
||||
config_dict = {}
|
||||
self.test_runner.init_config(config_dict, "testcase")
|
||||
|
||||
test = testcases[2]["test"]
|
||||
|
||||
Reference in New Issue
Block a user