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