mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
docs: update changelog and example tests
This commit is contained in:
+12
-1
@@ -1,12 +1,23 @@
|
|||||||
# Release History
|
# Release History
|
||||||
|
|
||||||
## 3.0.7 (2020-06-01)
|
## 3.0.7 (2020-06-03)
|
||||||
|
|
||||||
|
**Added**
|
||||||
|
|
||||||
|
- feat: make pytest files in chain style
|
||||||
|
|
||||||
**Fixed**
|
**Fixed**
|
||||||
|
|
||||||
- fix: convert jmespath.search result to int/float unintentionally
|
- fix: convert jmespath.search result to int/float unintentionally
|
||||||
- fix: referenced testcase should not be run duplicately
|
- fix: referenced testcase should not be run duplicately
|
||||||
- fix: requests.cookies.CookieConflictError, multiple cookies with name
|
- fix: requests.cookies.CookieConflictError, multiple cookies with name
|
||||||
|
- fix: missing exit code from pytest
|
||||||
|
- fix: skip invalid testcase/testsuite yaml/json file
|
||||||
|
|
||||||
|
**Changed**
|
||||||
|
|
||||||
|
- change: generate pytest in chain style by default
|
||||||
|
- docs: update sponsor info
|
||||||
|
|
||||||
## 3.0.6 (2020-05-29)
|
## 3.0.6 (2020-05-29)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
@@ -1,105 +1,76 @@
|
|||||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
# FROM: examples/httpbin/basic.yml
|
# FROM: examples/httpbin/basic.yml
|
||||||
|
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCaseBasic(HttpRunner):
|
class TestCaseBasic(HttpRunner):
|
||||||
config = TConfig(
|
config = Config("basic test with httpbin").base_url("https://httpbin.org/")
|
||||||
**{
|
|
||||||
"name": "basic test with httpbin",
|
|
||||||
"base_url": "https://httpbin.org/",
|
|
||||||
"path": "examples/httpbin/basic_test.py",
|
|
||||||
"variables": {},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
teststeps = [
|
teststeps = [
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("headers")
|
||||||
"name": "headers",
|
.get("/headers")
|
||||||
"request": {"url": "/headers", "method": "GET"},
|
.validate()
|
||||||
"validate": [
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("body.headers.Host", "httpbin.org")
|
||||||
{"eq": ["body.headers.Host", "httpbin.org"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("user-agent")
|
||||||
"name": "user-agent",
|
.get("/user-agent")
|
||||||
"request": {"url": "/user-agent", "method": "GET"},
|
.validate()
|
||||||
"validate": [
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["status_code", 200]},
|
.assert_startswith('body."user-agent"', "python-requests")
|
||||||
{"startswith": ['body."user-agent"', "python-requests"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get without params")
|
||||||
"name": "get without params",
|
.get("/get")
|
||||||
"request": {"url": "/get", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"eq": ["status_code", 200]}, {"eq": ["body.args", {}]}],
|
.assert_equal("status_code", 200)
|
||||||
}
|
.assert_equal("body.args", {})
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get with params in url")
|
||||||
"name": "get with params in url",
|
.get("/get?a=1&b=2")
|
||||||
"request": {"url": "/get?a=1&b=2", "method": "GET"},
|
.validate()
|
||||||
"validate": [
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("body.args", {"a": "1", "b": "2"})
|
||||||
{"eq": ["body.args", {"a": "1", "b": "2"}]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get with params in params field")
|
||||||
"name": "get with params in params field",
|
.get("/get")
|
||||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
.with_params(**{"a": 1, "b": 2})
|
||||||
"validate": [
|
.validate()
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["body.args", {"a": "1", "b": "2"}]},
|
.assert_equal("body.args", {"a": "1", "b": "2"})
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("set cookie")
|
||||||
"name": "set cookie",
|
.get("/cookies/set?name=value")
|
||||||
"request": {"url": "/cookies/set?name=value", "method": "GET"},
|
.validate()
|
||||||
"validate": [
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("body.cookies.name", "value")
|
||||||
{"eq": ["body.cookies.name", "value"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("extract cookie")
|
||||||
"name": "extract cookie",
|
.get("/cookies")
|
||||||
"request": {"url": "/cookies", "method": "GET"},
|
.validate()
|
||||||
"validate": [
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("body.cookies.name", "value")
|
||||||
{"eq": ["body.cookies.name", "value"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("post data")
|
||||||
"name": "post data",
|
.post("/post")
|
||||||
"request": {
|
.with_headers(**{"Content-Type": "application/json"})
|
||||||
"url": "/post",
|
.with_data("abc")
|
||||||
"method": "POST",
|
.validate()
|
||||||
"headers": {"Content-Type": "application/json"},
|
.assert_equal("status_code", 200)
|
||||||
"data": "abc",
|
|
||||||
},
|
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("validate body length")
|
||||||
"name": "validate body length",
|
.get("/spec.json")
|
||||||
"request": {"url": "/spec.json", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"len_eq": ["body", 9]}],
|
.assert_length_equal("body", 9)
|
||||||
}
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +1,27 @@
|
|||||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
# FROM: examples/httpbin/hooks.yml
|
# FROM: examples/httpbin/hooks.yml
|
||||||
|
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCaseHooks(HttpRunner):
|
class TestCaseHooks(HttpRunner):
|
||||||
config = TConfig(
|
config = Config("basic test with httpbin").base_url("${get_httpbin_server()}")
|
||||||
**{
|
|
||||||
"name": "basic test with httpbin",
|
|
||||||
"base_url": "${get_httpbin_server()}",
|
|
||||||
"setup_hooks": ["${hook_print(setup)}"],
|
|
||||||
"teardown_hooks": ["${hook_print(teardown)}"],
|
|
||||||
"path": "examples/httpbin/hooks_test.py",
|
|
||||||
"variables": {},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
teststeps = [
|
teststeps = [
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("headers")
|
||||||
"name": "headers",
|
.with_variables(**{"a": 123})
|
||||||
"variables": {"a": 123},
|
.get("/headers")
|
||||||
"request": {"url": "/headers", "method": "GET"},
|
.validate()
|
||||||
"setup_hooks": [
|
.assert_equal("status_code", 200)
|
||||||
"${setup_hook_add_kwargs($request)}",
|
.assert_contained_by("body.headers.Host", "${get_httpbin_server()}")
|
||||||
"${setup_hook_remove_kwargs($request)}",
|
|
||||||
],
|
|
||||||
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 1)}"],
|
|
||||||
"validate": [
|
|
||||||
{"eq": ["status_code", 200]},
|
|
||||||
{"contained_by": ["body.headers.Host", "${get_httpbin_server()}"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("alter response")
|
||||||
"name": "alter response",
|
.get("/headers")
|
||||||
"request": {"url": "/headers", "method": "GET"},
|
.validate()
|
||||||
"teardown_hooks": ["${alter_response($response)}"],
|
.assert_equal("status_code", 200)
|
||||||
"validate": [
|
.assert_equal("body.headers.Host", "httpbin.org")
|
||||||
{"eq": ["status_code", 200]},
|
|
||||||
{"eq": ["body.headers.Host", "httpbin.org"]},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,36 @@
|
|||||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
# FROM: examples/httpbin/load_image.yml
|
# FROM: examples/httpbin/load_image.yml
|
||||||
|
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCaseLoadImage(HttpRunner):
|
class TestCaseLoadImage(HttpRunner):
|
||||||
config = TConfig(
|
config = Config("load images").base_url("${get_httpbin_server()}")
|
||||||
**{
|
|
||||||
"name": "load images",
|
|
||||||
"base_url": "${get_httpbin_server()}",
|
|
||||||
"path": "examples/httpbin/load_image_test.py",
|
|
||||||
"variables": {},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
teststeps = [
|
teststeps = [
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get png image")
|
||||||
"name": "get png image",
|
.get("/image/png")
|
||||||
"request": {"url": "/image/png", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
.assert_equal("status_code", 200)
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get jpeg image")
|
||||||
"name": "get jpeg image",
|
.get("/image/jpeg")
|
||||||
"request": {"url": "/image/jpeg", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
.assert_equal("status_code", 200)
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get webp image")
|
||||||
"name": "get webp image",
|
.get("/image/webp")
|
||||||
"request": {"url": "/image/webp", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
.assert_equal("status_code", 200)
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("get svg image")
|
||||||
"name": "get svg image",
|
.get("/image/svg")
|
||||||
"request": {"url": "/image/svg", "method": "GET"},
|
.validate()
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
.assert_equal("status_code", 200)
|
||||||
}
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ teststeps:
|
|||||||
method: GET
|
method: GET
|
||||||
validate:
|
validate:
|
||||||
- eq: ["status_code", 200]
|
- eq: ["status_code", 200]
|
||||||
- eq: ["body.args.a", 1]
|
- eq: ["body.args.a", "1"]
|
||||||
- eq: ["body.args.b", 2]
|
- eq: ["body.args.b", "2"]
|
||||||
validate_script:
|
validate_script:
|
||||||
- "assert status_code == 200"
|
- "assert status_code == 200"
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,28 @@
|
|||||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
# FROM: examples/httpbin/validate.yml
|
# FROM: examples/httpbin/validate.yml
|
||||||
|
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCaseValidate(HttpRunner):
|
class TestCaseValidate(HttpRunner):
|
||||||
config = TConfig(
|
config = Config("basic test with httpbin").base_url("http://httpbin.org/")
|
||||||
**{
|
|
||||||
"name": "basic test with httpbin",
|
|
||||||
"base_url": "http://httpbin.org/",
|
|
||||||
"path": "examples/httpbin/validate_test.py",
|
|
||||||
"variables": {},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
teststeps = [
|
teststeps = [
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("validate response with json path")
|
||||||
"name": "validate response with json path",
|
.get("/get")
|
||||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
.with_params(**{"a": 1, "b": 2})
|
||||||
"validate": [
|
.validate()
|
||||||
{"eq": ["status_code", 200]},
|
.assert_equal("status_code", 200)
|
||||||
{"eq": ["body.args.a", 1]},
|
.assert_equal("body.args.a", "1")
|
||||||
{"eq": ["body.args.b", 2]},
|
.assert_equal("body.args.b", "2")
|
||||||
],
|
|
||||||
"validate_script": ["assert status_code == 200"],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
TStep(
|
Step(
|
||||||
**{
|
RunRequest("validate response with python script")
|
||||||
"name": "validate response with python script",
|
.get("/get")
|
||||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
.with_params(**{"a": 1, "b": 2})
|
||||||
"validate": [{"eq": ["status_code", 200]}],
|
.validate()
|
||||||
"validate_script": [
|
.assert_equal("status_code", 200)
|
||||||
"assert status_code == 201",
|
|
||||||
"a = response_json.get('args').get('a')",
|
|
||||||
"assert a == '1'",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,62 +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
|
|
||||||
|
|
||||||
summary["details"].append(testcase_summary.dict())
|
|
||||||
|
|
||||||
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}")
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user