mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: clear project_meta before each test
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@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}")
|
||||||
|
|
||||||
+2
-1
@@ -40,9 +40,10 @@ class TestCli(unittest.TestCase):
|
|||||||
self.assertIn(__description__, self.captured_output.getvalue().strip())
|
self.assertIn(__description__, self.captured_output.getvalue().strip())
|
||||||
|
|
||||||
def test_debug_pytest(self):
|
def test_debug_pytest(self):
|
||||||
pytest.main(
|
exit_code = pytest.main(
|
||||||
[
|
[
|
||||||
"-s",
|
"-s",
|
||||||
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
|
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
self.assertEqual(exit_code, 0)
|
||||||
|
|||||||
+6
-4
@@ -9,9 +9,15 @@ from httprunner.make import (
|
|||||||
make_teststep_chain_style,
|
make_teststep_chain_style,
|
||||||
pytest_files_run_set,
|
pytest_files_run_set,
|
||||||
)
|
)
|
||||||
|
from httprunner import loader
|
||||||
|
|
||||||
|
|
||||||
class TestMake(unittest.TestCase):
|
class TestMake(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
pytest_files_made_cache_mapping.clear()
|
||||||
|
pytest_files_run_set.clear()
|
||||||
|
loader.project_meta = None
|
||||||
|
|
||||||
def test_make_testcase(self):
|
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)
|
testcase_python_list = main_make(path)
|
||||||
@@ -27,8 +33,6 @@ class TestMake(unittest.TestCase):
|
|||||||
path = [
|
path = [
|
||||||
"examples/postman-echo/request.methods/request_with_testcase_reference.yml"
|
"examples/postman-echo/request.methods/request_with_testcase_reference.yml"
|
||||||
]
|
]
|
||||||
pytest_files_made_cache_mapping.clear()
|
|
||||||
pytest_files_run_set.clear()
|
|
||||||
testcase_python_list = main_make(path)
|
testcase_python_list = main_make(path)
|
||||||
self.assertEqual(len(testcase_python_list), 1)
|
self.assertEqual(len(testcase_python_list), 1)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
@@ -90,8 +94,6 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
|||||||
|
|
||||||
def test_make_testsuite(self):
|
def test_make_testsuite(self):
|
||||||
path = ["examples/postman-echo/request.methods/demo_testsuite.yml"]
|
path = ["examples/postman-echo/request.methods/demo_testsuite.yml"]
|
||||||
pytest_files_made_cache_mapping.clear()
|
|
||||||
pytest_files_run_set.clear()
|
|
||||||
testcase_python_list = main_make(path)
|
testcase_python_list = main_make(path)
|
||||||
self.assertEqual(len(testcase_python_list), 2)
|
self.assertEqual(len(testcase_python_list), 2)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from httprunner import loader
|
||||||
from httprunner.runner import HttpRunner
|
from httprunner.runner import HttpRunner
|
||||||
|
|
||||||
|
|
||||||
class TestHttpRunner(unittest.TestCase):
|
class TestHttpRunner(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
loader.project_meta = None
|
||||||
self.runner = HttpRunner()
|
self.runner = HttpRunner()
|
||||||
|
|
||||||
def test_run_testcase_by_path_request_only(self):
|
def test_run_testcase_by_path_request_only(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user