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