Skip to content

Commit 31b4af9

Browse files
committed
fix
1 parent 16ed43e commit 31b4af9

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎pytest/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "testsolar-pytestx"
3-
version = "0.1.62"
3+
version = "0.1.63"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/executor.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class RunMode(Enum):
4848
BATCH = "batch"
4949

5050

51+
def should_enable_header_injection() -> bool:
52+
"""判断是否需要启用请求头注入功能"""
53+
return os.environ.get("ENABLE_API_COLLECTING", "") == "1"
54+
55+
56+
if should_enable_header_injection():
57+
initialize_header_injection()
58+
59+
5160
class PytestExecutor:
5261
def __init__(
5362
self,
@@ -62,13 +71,6 @@ def __init__(
6271
self.comment_fields = comment_fields
6372
self.data_drive_key = data_drive_key
6473

65-
# 初始化API请求头注入功能,传入判定方法
66-
initialize_header_injection()
67-
68-
def _should_enable_header_injection(self) -> bool:
69-
"""判断是否需要启用请求头注入功能"""
70-
return os.environ.get("ENABLE_API_COLLECTING", "") == "1"
71-
7274
def pytest_runtest_logstart(self, nodeid: str, location: Any) -> None:
7375
"""
7476
Called at the start of running the runtest protocol for a single item.
@@ -79,7 +81,7 @@ def pytest_runtest_logstart(self, nodeid: str, location: Any) -> None:
7981
testcase_name = normalize_testcase_name(nodeid, self.data_drive_key)
8082

8183
# 设置当前测试用例的nodeid到上下文
82-
if self._should_enable_header_injection():
84+
if should_enable_header_injection():
8385
testcase_class_name = testcase_name.split("?", 1)[-1]
8486
set_current_test_nodeid(testcase_class_name)
8587

@@ -228,7 +230,7 @@ def pytest_runtest_logfinish(self, nodeid: str, location: Any) -> None:
228230
self.testdata.pop(testcase_name, None)
229231

230232
# 清除当前测试用例的nodeid
231-
if self._should_enable_header_injection():
233+
if should_enable_header_injection():
232234
set_current_test_nodeid(None)
233235

234236
logger.info(f"E {nodeid} runtest_logfinish")

‎pytest/testtool.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schemaVersion: 1.0
22
name: pytest
33
nameZh: pytest自动化测试
44
lang: python
5-
version: '0.1.62'
5+
version: '0.1.63'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

‎pytest/uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)