From 97557a9b6f33d276041262d7852c27e634e4df5f Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 8 Jun 2020 16:26:56 +0800 Subject: [PATCH] docs: update changelog --- docs/CHANGELOG.md | 7 ++++ examples/httpbin/basic_test.py | 2 +- examples/httpbin/conftest.py | 64 +++++++++++++++++++++++++++++ examples/httpbin/hooks_test.py | 2 +- examples/httpbin/load_image_test.py | 2 +- examples/httpbin/upload_test.py | 2 +- examples/httpbin/validate_test.py | 2 +- httprunner/make.py | 10 ++--- 8 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 examples/httpbin/conftest.py diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a3137538..25059107 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,13 @@ ## 3.0.11 (2020-06-08) +**Changed** + +- change: override variables + (1) testcase: session variables > step variables > config variables + (2) testsuite: testcase variables > config variables + (3) testsuite testcase variables > testcase config variables + **Fixed** - fix: incorrect summary success when testcase failed diff --git a/examples/httpbin/basic_test.py b/examples/httpbin/basic_test.py index 4fe82d84..aa650da2 100644 --- a/examples/httpbin/basic_test.py +++ b/examples/httpbin/basic_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.0.10 +# NOTE: Generated By HttpRunner v3.0.11 # FROM: examples/httpbin/basic.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/conftest.py b/examples/httpbin/conftest.py new file mode 100644 index 00000000..5bb3d816 --- /dev/null +++ b/examples/httpbin/conftest.py @@ -0,0 +1,64 @@ +# NOTICE: Generated By HttpRunner. +import json +import os +import time + +import pytest +from loguru import logger + +from httprunner.utils import get_platform, ExtendJSONEncoder + + +@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/httpbin/logs/upload.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, ensure_ascii=False, cls=ExtendJSONEncoder) + + logger.info(f"generated task summary: {summary_path}") + diff --git a/examples/httpbin/hooks_test.py b/examples/httpbin/hooks_test.py index 5ae2da61..e090cada 100644 --- a/examples/httpbin/hooks_test.py +++ b/examples/httpbin/hooks_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.0.10 +# NOTE: Generated By HttpRunner v3.0.11 # FROM: examples/httpbin/hooks.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/load_image_test.py b/examples/httpbin/load_image_test.py index cd21fb69..38203afb 100644 --- a/examples/httpbin/load_image_test.py +++ b/examples/httpbin/load_image_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.0.10 +# NOTE: Generated By HttpRunner v3.0.11 # FROM: examples/httpbin/load_image.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/upload_test.py b/examples/httpbin/upload_test.py index fa100f85..6d80b78e 100644 --- a/examples/httpbin/upload_test.py +++ b/examples/httpbin/upload_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.0.10 +# NOTE: Generated By HttpRunner v3.0.11 # FROM: examples/httpbin/upload.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/validate_test.py b/examples/httpbin/validate_test.py index 281a94fb..6826d6dd 100644 --- a/examples/httpbin/validate_test.py +++ b/examples/httpbin/validate_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.0.10 +# NOTE: Generated By HttpRunner v3.0.11 # FROM: examples/httpbin/validate.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/httprunner/make.py b/httprunner/make.py index b4b24ae1..2e842213 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -453,18 +453,18 @@ def __make(tests_path: Text) -> NoReturn: continue if not isinstance(test_content, Dict): - raise exceptions.FileFormatError( - f"test content not in dict format: {test_content}" - ) + logger.warning(f"test content not in dict format. \npath: {test_file}") + continue # api in v2 format, convert to v3 testcase if "request" in test_content and "name" in test_content: test_content = ensure_testcase_v3_api(test_content) if "config" not in test_content: - raise exceptions.FileFormatError( - f"miss config part in testcase/testsuite: {test_content}" + logger.warning( + f"Invalid testcase/testsuite: missing config part in testcase/testsuite.\npath: {test_file}" ) + continue test_content.setdefault("config", {})["path"] = test_file