mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 09:17:43 +08:00
test: update tests
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
from httprunner import __version__
|
||||
|
||||
|
||||
def get_httprunner_version():
|
||||
return __version__
|
||||
|
||||
|
||||
def sum_two(m, n):
|
||||
return m + n
|
||||
|
||||
|
||||
def get_variables():
|
||||
return {"foo1": "session_bar1"}
|
||||
@@ -1,64 +0,0 @@
|
||||
# NOTICE: Generated By HttpRunner.
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
||||
from httprunner.utils import get_platform
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def session_fixture(request):
|
||||
"""setup and teardown each task"""
|
||||
logger.info(f"start running testcases ...")
|
||||
|
||||
start_at = time.time()
|
||||
|
||||
yield
|
||||
|
||||
logger.info(f"task finished, generate task summary for --save-tests")
|
||||
|
||||
summary = {
|
||||
"success": True,
|
||||
"stat": {
|
||||
"testcases": {"total": 0, "success": 0, "fail": 0},
|
||||
"teststeps": {"total": 0, "failures": 0, "successes": 0},
|
||||
},
|
||||
"time": {"start_at": start_at, "duration": time.time() - start_at},
|
||||
"platform": get_platform(),
|
||||
"details": [],
|
||||
}
|
||||
|
||||
for item in request.node.items:
|
||||
testcase_summary = item.instance.get_summary()
|
||||
summary["success"] &= testcase_summary.success
|
||||
|
||||
summary["stat"]["testcases"]["total"] += 1
|
||||
summary["stat"]["teststeps"]["total"] += len(testcase_summary.step_datas)
|
||||
if testcase_summary.success:
|
||||
summary["stat"]["testcases"]["success"] += 1
|
||||
summary["stat"]["teststeps"]["successes"] += len(
|
||||
testcase_summary.step_datas
|
||||
)
|
||||
else:
|
||||
summary["stat"]["testcases"]["fail"] += 1
|
||||
summary["stat"]["teststeps"]["successes"] += (
|
||||
len(testcase_summary.step_datas) - 1
|
||||
)
|
||||
summary["stat"]["teststeps"]["failures"] += 1
|
||||
|
||||
testcase_summary_json = testcase_summary.dict()
|
||||
testcase_summary_json["records"] = testcase_summary_json.pop("step_datas")
|
||||
summary["details"].append(testcase_summary_json)
|
||||
|
||||
summary_path = "/Users/debugtalk/MyProjects/HttpRunner-dev/HttpRunner/examples/postman_echo/logs/request.methods/hardcode.summary.json"
|
||||
summary_dir = os.path.dirname(summary_path)
|
||||
os.makedirs(summary_dir, exist_ok=True)
|
||||
|
||||
with open(summary_path, "w", encoding="utf-8") as f:
|
||||
json.dump(summary, f, indent=4)
|
||||
|
||||
logger.info(f"generated task summary: {summary_path}")
|
||||
|
||||
@@ -5,11 +5,11 @@ config:
|
||||
testcases:
|
||||
-
|
||||
name: request with functions
|
||||
testcase: request.methods/request_with_functions.yml
|
||||
testcase: request_methods/request_with_functions.yml
|
||||
variables:
|
||||
var1: testsuite_val1
|
||||
-
|
||||
name: request with referenced testcase
|
||||
testcase: request.methods/request_with_testcase_reference.yml
|
||||
testcase: request_methods/request_with_testcase_reference.yml
|
||||
variables:
|
||||
var2: testsuite_val2
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/request_with_functions.yml
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/request_with_testcase_reference.yml
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/hardcode.yml
|
||||
# FROM: examples/postman_echo/request_methods/hardcode.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/request_with_functions.yml
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ teststeps:
|
||||
name: request with functions
|
||||
variables:
|
||||
foo1: override_bar1
|
||||
testcase: request.methods/request_with_functions.yml
|
||||
testcase: request_methods/request_with_functions.yml
|
||||
export:
|
||||
- session_foo2
|
||||
-
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/request_with_testcase_reference.yml
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/request_with_variables.yml
|
||||
# FROM: examples/postman_echo/request_methods/request_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/validate_with_functions.yml
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman-echo/request.methods/validate_with_variables.yml
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -142,28 +142,28 @@ class TestCompat(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_ensure_cli_args(self):
|
||||
args1 = ["examples/postman-echo/request.methods/hardcode.yml", "--failfast"]
|
||||
args1 = ["examples/postman_echo/request_methods/hardcode.yml", "--failfast"]
|
||||
self.assertEqual(
|
||||
compat.ensure_cli_args(args1),
|
||||
["examples/postman-echo/request.methods/hardcode.yml"],
|
||||
["examples/postman_echo/request_methods/hardcode.yml"],
|
||||
)
|
||||
|
||||
args2 = ["examples/postman-echo/request.methods/hardcode.yml", "--save-tests"]
|
||||
args2 = ["examples/postman_echo/request_methods/hardcode.yml", "--save-tests"]
|
||||
self.assertEqual(
|
||||
compat.ensure_cli_args(args2),
|
||||
["examples/postman-echo/request.methods/hardcode.yml"],
|
||||
["examples/postman_echo/request_methods/hardcode.yml"],
|
||||
)
|
||||
self.assertTrue(os.path.isfile("examples/postman_echo/conftest.py"))
|
||||
|
||||
args3 = [
|
||||
"examples/postman-echo/request.methods/hardcode.yml",
|
||||
"examples/postman_echo/request_methods/hardcode.yml",
|
||||
"--report-file",
|
||||
"report.html",
|
||||
]
|
||||
self.assertEqual(
|
||||
compat.ensure_cli_args(args3),
|
||||
[
|
||||
"examples/postman-echo/request.methods/hardcode.yml",
|
||||
"examples/postman_echo/request_methods/hardcode.yml",
|
||||
"--html",
|
||||
"report.html",
|
||||
"--self-contained-html",
|
||||
@@ -171,7 +171,7 @@ class TestCompat(unittest.TestCase):
|
||||
)
|
||||
|
||||
args4 = [
|
||||
"examples/postman-echo/request.methods/hardcode.yml",
|
||||
"examples/postman_echo/request_methods/hardcode.yml",
|
||||
"--failfast",
|
||||
"--save-tests",
|
||||
"--report-file",
|
||||
@@ -180,7 +180,7 @@ class TestCompat(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
compat.ensure_cli_args(args4),
|
||||
[
|
||||
"examples/postman-echo/request.methods/hardcode.yml",
|
||||
"examples/postman_echo/request_methods/hardcode.yml",
|
||||
"--html",
|
||||
"report.html",
|
||||
"--self-contained-html",
|
||||
|
||||
@@ -6,7 +6,7 @@ from httprunner import exceptions, loader
|
||||
|
||||
class TestLoader(unittest.TestCase):
|
||||
def test_load_testcase_file(self):
|
||||
path = "examples/postman-echo/request.methods/request_with_variables.yml"
|
||||
path = "examples/postman_echo/request_methods/request_with_variables.yml"
|
||||
testcase_obj = loader.load_testcase_file(path)
|
||||
self.assertEqual(
|
||||
testcase_obj.config.name, "request methods testcase with variables"
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestMake(unittest.TestCase):
|
||||
loader.project_meta = None
|
||||
|
||||
def test_make_testcase(self):
|
||||
path = ["examples/postman-echo/request.methods/request_with_variables.yml"]
|
||||
path = ["examples/postman_echo/request_methods/request_with_variables.yml"]
|
||||
testcase_python_list = main_make(path)
|
||||
self.assertEqual(
|
||||
testcase_python_list[0],
|
||||
@@ -31,7 +31,7 @@ class TestMake(unittest.TestCase):
|
||||
|
||||
def test_make_testcase_with_ref(self):
|
||||
path = [
|
||||
"examples/postman-echo/request.methods/request_with_testcase_reference.yml"
|
||||
"examples/postman_echo/request_methods/request_with_testcase_reference.yml"
|
||||
]
|
||||
testcase_python_list = main_make(path)
|
||||
self.assertEqual(len(testcase_python_list), 1)
|
||||
@@ -60,7 +60,7 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
)
|
||||
|
||||
def test_make_testcase_folder(self):
|
||||
path = ["examples/postman-echo/request.methods/"]
|
||||
path = ["examples/postman_echo/request_methods/"]
|
||||
testcase_python_list = main_make(path)
|
||||
self.assertIn(
|
||||
os.path.join(
|
||||
@@ -93,7 +93,7 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
)
|
||||
|
||||
def test_make_testsuite(self):
|
||||
path = ["examples/postman-echo/request.methods/demo_testsuite.yml"]
|
||||
path = ["examples/postman_echo/request_methods/demo_testsuite.yml"]
|
||||
testcase_python_list = main_make(path)
|
||||
self.assertEqual(len(testcase_python_list), 2)
|
||||
self.assertIn(
|
||||
@@ -115,13 +115,13 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
config = {
|
||||
"name": "request methods testcase: validate with functions",
|
||||
"variables": {"foo1": "bar1", "foo2": 22},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"base_url": "https://postman_echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/validate_with_functions_test.py",
|
||||
}
|
||||
self.assertEqual(
|
||||
make_config_chain_style(config),
|
||||
"""Config("request methods testcase: validate with functions").variables(**{'foo1': 'bar1', 'foo2': 22}).base_url("https://postman-echo.com").verify(False)""",
|
||||
"""Config("request methods testcase: validate with functions").variables(**{'foo1': 'bar1', 'foo2': 22}).base_url("https://postman_echo.com").verify(False)""",
|
||||
)
|
||||
|
||||
def test_make_teststep_chain_style(self):
|
||||
|
||||
@@ -11,7 +11,7 @@ class TestHttpRunner(unittest.TestCase):
|
||||
|
||||
def test_run_testcase_by_path_request_only(self):
|
||||
self.runner.run_path(
|
||||
"examples/postman-echo/request.methods/request_with_functions.yml"
|
||||
"examples/postman_echo/request_methods/request_with_functions.yml"
|
||||
)
|
||||
result = self.runner.get_summary()
|
||||
self.assertTrue(result.success)
|
||||
@@ -21,7 +21,7 @@ class TestHttpRunner(unittest.TestCase):
|
||||
|
||||
def test_run_testcase_by_path_ref_testcase(self):
|
||||
self.runner.run_path(
|
||||
"examples/postman-echo/request.methods/request_with_testcase_reference.yml"
|
||||
"examples/postman_echo/request_methods/request_with_testcase_reference.yml"
|
||||
)
|
||||
result = self.runner.get_summary()
|
||||
self.assertTrue(result.success)
|
||||
|
||||
@@ -102,24 +102,10 @@ class TestUtils(unittest.TestCase):
|
||||
def test_ensure_file_path_valid(self):
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid(
|
||||
"examples/postman-echo/request.methods/hardcode.yml"
|
||||
"examples/a-b.c/d f/hardcode.yml"
|
||||
),
|
||||
os.path.join(
|
||||
os.getcwd(), "examples/postman_echo/request_methods/hardcode.yml"
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid(
|
||||
os.path.join(os.getcwd(), "postman-echo/request.methods/hardcode.yml")
|
||||
),
|
||||
os.path.join(os.getcwd(), "postman_echo/request_methods/hardcode.yml"),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid(
|
||||
"examples/postman echo/request methods/hardcode.yml"
|
||||
),
|
||||
os.path.join(
|
||||
os.getcwd(), "examples/postman_echo/request_methods/hardcode.yml"
|
||||
os.getcwd(), "examples/a_b_c/d_f/hardcode.yml"
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
@@ -127,6 +113,14 @@ class TestUtils(unittest.TestCase):
|
||||
os.path.join(os.getcwd(), "T1/T2B/T3.yml"),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid("examples/postman-echo/request.methods/"),
|
||||
ensure_file_path_valid(
|
||||
"examples/a-b.c/2B/hardcode.yml"
|
||||
),
|
||||
os.path.join(
|
||||
os.getcwd(), "examples/a_b_c/T2B/hardcode.yml"
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid("examples/postman_echo/request_methods/"),
|
||||
os.path.join(os.getcwd(), "examples/postman_echo/request_methods"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user