pytest-platform-adapter 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest_platform_adapter
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Pytest集成自动化平台插件
5
5
  Author-email: BlackYau <blackyau426@gmail.com>
6
6
  Maintainer-email: BlackYau <blackyau426@gmail.com>
@@ -87,7 +87,8 @@ pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple pytest-platf
87
87
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
88
88
 
89
89
  ```
90
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
90
+ # 需要把下面的 x.x.x 替换为实际的版本号
91
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
91
92
  ```
92
93
 
93
94
  #### 国内镜像站下载离线安装
@@ -99,7 +100,8 @@ pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
99
100
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
100
101
 
101
102
  ```
102
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
103
+ # 需要把下面的 x.x.x 替换为实际的版本号
104
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
103
105
  ```
104
106
 
105
107
  ## 使用方法
@@ -193,17 +195,22 @@ platform_env_behavior_checks =
193
195
  tests/env_check/test_function_env_check.py::TestFunctionEnvCheck
194
196
  platform_env_behavior_scope = epic # epic / feature / story
195
197
  platform_env_fail_action = skip # skip / xfail / none
198
+ platform_env_collect_mode = force # force / auto
196
199
  ```
197
200
 
198
201
  - `platform_env_global_checks`:在每次用例执行前跑一遍的检查用例列表。
199
202
  - `platform_env_behavior_checks`:特性级检查用例列表,插件会读取这些用例标签并在同一特性的首个用例前插入执行。
200
203
  - `platform_env_behavior_scope`:定义特性的级别可选的有 epic/feature/story(分别对应 Allure Report 的 behaviors 中的一级目录、二级目录、三级目录)
201
204
  - `platform_env_fail_action`:检查失败后对后续业务用例的处理方式,`skip` 为直接跳过、`xfail` 为继续执行并动态加上 `xfail`(失败记为 XFAIL、通过记为 XPASS)、`none` 仅记录日志不干预执行。
205
+ - `platform_env_collect_mode`:环境检查收集模式,默认 `force`。
206
+ - `force`(强制):即使本次命令行只收集了业务目录,也会强制把 `platform_env_global_checks` / `platform_env_behavior_checks` 声明的 NodeID 注入收集范围;环境检查用例不受 `-m`/`-k` 等筛选影响永远执行;全局检查永远执行;特性级检查仅在本次业务用例中存在同一行为标签(scope 对应 epic/feature/story)的情况下才执行,没有匹配的特性级检查不会执行。
207
+ - `auto`(自动):不额外注入收集参数,仅执行本次 pytest 收集到的检查用例;如果声明的 NodeID 没有被收集到则不会执行。
202
208
 
203
209
  #### 命令行
204
210
 
205
211
  - `--env-check-mode={off,global,behavior,all}`:快速控制启用的检查范围。
206
212
  - `--env-check-scope=<epic|feature|story>`:临时覆盖行为层级设定。
213
+ - `--env-check-collect-mode={force,auto}`:临时覆盖 `platform_env_collect_mode`,控制环境检查的收集/执行策略。
207
214
  - 当 `platform_env_fail_action=xfail` 时,会在受影响的业务用例上自动添加 `pytest.mark.xfail(run=True, strict=False)`,用例依旧执行,只是失败时记为 XFAIL。
208
215
 
209
216
  当检查用例失败时,插件会在 `pytest_runtest_setup` 阶段统一对后续业务用例执行 `skip` 或 `xfail`,并在日志中说明对应的检查节点。检查用例自身依旧遵循 pytest 原生语义,可继续使用 `skip/xfail/flaky` 等标记。
@@ -51,7 +51,8 @@ pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple pytest-platf
51
51
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
52
52
 
53
53
  ```
54
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
54
+ # 需要把下面的 x.x.x 替换为实际的版本号
55
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
55
56
  ```
56
57
 
57
58
  #### 国内镜像站下载离线安装
@@ -63,7 +64,8 @@ pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
63
64
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
64
65
 
65
66
  ```
66
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
67
+ # 需要把下面的 x.x.x 替换为实际的版本号
68
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
67
69
  ```
68
70
 
69
71
  ## 使用方法
@@ -157,17 +159,22 @@ platform_env_behavior_checks =
157
159
  tests/env_check/test_function_env_check.py::TestFunctionEnvCheck
158
160
  platform_env_behavior_scope = epic # epic / feature / story
159
161
  platform_env_fail_action = skip # skip / xfail / none
162
+ platform_env_collect_mode = force # force / auto
160
163
  ```
161
164
 
162
165
  - `platform_env_global_checks`:在每次用例执行前跑一遍的检查用例列表。
163
166
  - `platform_env_behavior_checks`:特性级检查用例列表,插件会读取这些用例标签并在同一特性的首个用例前插入执行。
164
167
  - `platform_env_behavior_scope`:定义特性的级别可选的有 epic/feature/story(分别对应 Allure Report 的 behaviors 中的一级目录、二级目录、三级目录)
165
168
  - `platform_env_fail_action`:检查失败后对后续业务用例的处理方式,`skip` 为直接跳过、`xfail` 为继续执行并动态加上 `xfail`(失败记为 XFAIL、通过记为 XPASS)、`none` 仅记录日志不干预执行。
169
+ - `platform_env_collect_mode`:环境检查收集模式,默认 `force`。
170
+ - `force`(强制):即使本次命令行只收集了业务目录,也会强制把 `platform_env_global_checks` / `platform_env_behavior_checks` 声明的 NodeID 注入收集范围;环境检查用例不受 `-m`/`-k` 等筛选影响永远执行;全局检查永远执行;特性级检查仅在本次业务用例中存在同一行为标签(scope 对应 epic/feature/story)的情况下才执行,没有匹配的特性级检查不会执行。
171
+ - `auto`(自动):不额外注入收集参数,仅执行本次 pytest 收集到的检查用例;如果声明的 NodeID 没有被收集到则不会执行。
166
172
 
167
173
  #### 命令行
168
174
 
169
175
  - `--env-check-mode={off,global,behavior,all}`:快速控制启用的检查范围。
170
176
  - `--env-check-scope=<epic|feature|story>`:临时覆盖行为层级设定。
177
+ - `--env-check-collect-mode={force,auto}`:临时覆盖 `platform_env_collect_mode`,控制环境检查的收集/执行策略。
171
178
  - 当 `platform_env_fail_action=xfail` 时,会在受影响的业务用例上自动添加 `pytest.mark.xfail(run=True, strict=False)`,用例依旧执行,只是失败时记为 XFAIL。
172
179
 
173
180
  当检查用例失败时,插件会在 `pytest_runtest_setup` 阶段统一对后续业务用例执行 `skip` 或 `xfail`,并在日志中说明对应的检查节点。检查用例自身依旧遵循 pytest 原生语义,可继续使用 `skip/xfail/flaky` 等标记。
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytest_platform_adapter"
7
- version = "1.1.0"
7
+ version = "1.2.0"
8
8
  dependencies = [
9
9
  "pytest>=6.2.5",
10
10
  "allure-pytest>=2.9.45"
@@ -37,6 +37,7 @@ ENV_RUNTIME_KEY: StashKey["EnvCheckRuntime"] = StashKey()
37
37
  ITEM_KIND_KEY: StashKey[str] = StashKey()
38
38
  BEHAVIOR_KEY: StashKey[Optional[str]] = StashKey()
39
39
  ENV_XFAIL_REASON_KEY: StashKey[Optional[str]] = StashKey()
40
+ FORCED_ITEMS_KEY: StashKey[List[pytest.Item]] = StashKey()
40
41
  STASH_SENTINEL = object()
41
42
 
42
43
 
@@ -45,6 +46,7 @@ class EnvCheckSettings:
45
46
  mode: str = 'all'
46
47
  behavior_scope: str = 'feature'
47
48
  fail_action: str = 'skip'
49
+ collect_mode: str = 'force' # force(强制)/auto(自动)
48
50
  global_nodeids: List[str] = field(default_factory=list)
49
51
  behavior_nodeids: List[str] = field(default_factory=list)
50
52
 
@@ -104,6 +106,13 @@ def pytest_addoption(parser):
104
106
  default=None,
105
107
  help='特性级检查所使用的 Allure 标签层级:epic/feature/story'
106
108
  )
109
+ group.addoption(
110
+ '--env-check-collect-mode',
111
+ action='store',
112
+ default=None,
113
+ choices=['force', 'auto'],
114
+ help='环境检查收集模式覆盖:force(强制收集并执行)/auto(仅执行已收集到的检查用例)'
115
+ )
107
116
  parser.addini(
108
117
  'platform_ip',
109
118
  help='自动化平台API IP',
@@ -146,8 +155,13 @@ def pytest_addoption(parser):
146
155
  help='环境检查失败后对业务用例的处理方式(skip/xfail/none)',
147
156
  default='skip'
148
157
  )
158
+ parser.addini(
159
+ 'platform_env_collect_mode',
160
+ help='环境检查收集模式:force(强制收集并执行)/auto(仅执行已收集到的检查用例)',
161
+ default='force'
162
+ )
149
163
 
150
-
164
+ @pytest.hookimpl(tryfirst=True, hookwrapper=True)
151
165
  def pytest_collection_modifyitems(config, items):
152
166
  """
153
167
  hook收集用例的过程,给--case_ids和--case_ids_file提供支持
@@ -155,8 +169,27 @@ def pytest_collection_modifyitems(config, items):
155
169
  """
156
170
  settings = get_env_settings(config)
157
171
  forced_nodeids = _collect_forced_nodeids(settings)
158
- initial_nodeids = {item.nodeid for item in items}
159
- for missing in sorted(forced_nodeids - initial_nodeids):
172
+ # 预先快照强制环境检查用例,供后续无视 -m / -k 过滤使用。
173
+ if env_checks_enabled(settings) and settings.collect_mode == 'force':
174
+ forced_items: List[pytest.Item] = []
175
+ seen: Set[str] = set()
176
+ for item in items:
177
+ if _is_forced_item(item.nodeid, forced_nodeids) and item.nodeid not in seen:
178
+ forced_items.append(item)
179
+ seen.add(item.nodeid)
180
+ config.stash[FORCED_ITEMS_KEY] = forced_items
181
+ yield
182
+ # 缺失检查告警:force 模式下使用 pre-deselect 的快照判断,避免被 -m/-k 误判。
183
+ if env_checks_enabled(settings) and settings.collect_mode == 'force':
184
+ forced_items_snapshot = config.stash.get(FORCED_ITEMS_KEY, [])
185
+ available_ids = {item.nodeid for item in forced_items_snapshot}
186
+ else:
187
+ available_ids = {item.nodeid for item in items}
188
+ missing_forced: List[str] = []
189
+ for prefix in forced_nodeids:
190
+ if not any(n == prefix or n.startswith(prefix + "::") for n in available_ids):
191
+ missing_forced.append(prefix)
192
+ for missing in sorted(missing_forced):
160
193
  logger.warning(f"配置的环境检查用例 {missing} 未被收集,检查 NodeID 是否正确")
161
194
 
162
195
  target_ids = get_target_test_ids(config)
@@ -164,7 +197,7 @@ def pytest_collection_modifyitems(config, items):
164
197
  deselected = []
165
198
  for item in items:
166
199
  nodeid = item.nodeid
167
- should_force_run = nodeid in forced_nodeids
200
+ should_force_run = _is_forced_item(nodeid, forced_nodeids)
168
201
  title = allure_title(item)
169
202
  test_id = get_test_id_from_title(title)
170
203
  if not target_ids or should_force_run or test_id in target_ids:
@@ -182,6 +215,16 @@ def pytest_collection_modifyitems(config, items):
182
215
  if deselected:
183
216
  config.hook.pytest_deselected(items=deselected)
184
217
  items[:] = selected
218
+
219
+ # force 模式下无视 -m / -k 的 deselect:把缓存的环境检查重新插回来
220
+ if env_checks_enabled(settings) and settings.collect_mode == 'force':
221
+ forced_items = config.stash.get(FORCED_ITEMS_KEY, [])
222
+ current_ids = {item.nodeid for item in items}
223
+ for forced_item in forced_items:
224
+ if forced_item.nodeid not in current_ids:
225
+ items.append(forced_item)
226
+ current_ids.add(forced_item.nodeid)
227
+
185
228
  selected_ids = [get_test_id_from_title(allure_title(item)) for item in items]
186
229
  test_stats['total'] = len(items) # 更新总用例数
187
230
  if target_ids:
@@ -339,6 +382,32 @@ def pytest_configure(config):
339
382
  settings = build_env_check_settings(config)
340
383
  config.stash[ENV_SETTINGS_KEY] = settings
341
384
  config.stash[ENV_RUNTIME_KEY] = EnvCheckRuntime()
385
+ # 在强制模式下,将声明的环境检查 NodeID 注入到 pytest 收集参数中,
386
+ # 以保证即使用户只选择了业务目录也能收集到检查用例。
387
+ if env_checks_enabled(settings) and settings.collect_mode == 'force':
388
+ try:
389
+ from pathlib import Path
390
+
391
+ existing_args = set(config.args or [])
392
+ rootpath = getattr(config, "rootpath", Path.cwd())
393
+ forced_args: List[str] = []
394
+ for nodeid in _collect_forced_nodeids(settings):
395
+ if nodeid in existing_args:
396
+ continue
397
+ # 仅对文件路径存在的 NodeID 进行注入,避免明显的 not found。
398
+ path_part = nodeid.split("::", 1)[0]
399
+ p = Path(path_part)
400
+ if not p.is_absolute():
401
+ p = rootpath / p
402
+ if p.exists():
403
+ forced_args.append(nodeid)
404
+ else:
405
+ logger.warning("强制收集环境检查失败:文件不存在 %s", nodeid)
406
+ if forced_args:
407
+ config.args.extend(forced_args)
408
+ logger.debug("已强制注入环境检查收集参数: %s", forced_args)
409
+ except Exception as e:
410
+ logger.warning("强制收集环境检查参数注入异常:%s", e)
342
411
  pipeline_name = os.environ.get("JOB_NAME")
343
412
  build_number = os.environ.get("BUILD_NUMBER")
344
413
  handler = logging.StreamHandler()
@@ -412,6 +481,16 @@ def build_env_check_settings(config) -> EnvCheckSettings:
412
481
  if fail_action not in {'skip', 'xfail', 'none'}:
413
482
  logger.warning("platform_env_fail_action=%s 不受支持,改用 skip", fail_action_raw)
414
483
  fail_action = 'skip'
484
+ collect_mode_opt = config.getoption('--env-check-collect-mode')
485
+ collect_mode_raw = collect_mode_opt or config.getini('platform_env_collect_mode')
486
+ collect_mode = (collect_mode_raw or 'force').strip().lower()
487
+ if collect_mode in {'强制'}:
488
+ collect_mode = 'force'
489
+ elif collect_mode in {'自动'}:
490
+ collect_mode = 'auto'
491
+ if collect_mode not in {'force', 'auto'}:
492
+ logger.warning("platform_env_collect_mode=%s 不受支持,改用 force", collect_mode_raw)
493
+ collect_mode = 'force'
415
494
  global_nodes = _normalize_nodeids(config.getini('platform_env_global_checks'))
416
495
  behavior_nodes = _normalize_nodeids(config.getini('platform_env_behavior_checks'))
417
496
  if mode not in {'off', 'global', 'behavior', 'all'}:
@@ -421,6 +500,7 @@ def build_env_check_settings(config) -> EnvCheckSettings:
421
500
  mode=mode,
422
501
  behavior_scope=scope,
423
502
  fail_action=fail_action,
503
+ collect_mode=collect_mode,
424
504
  global_nodeids=global_nodes,
425
505
  behavior_nodeids=behavior_nodes,
426
506
  )
@@ -462,40 +542,54 @@ def _collect_forced_nodeids(settings: Optional[EnvCheckSettings]) -> Set[str]:
462
542
  return forced
463
543
 
464
544
 
545
+ def _is_forced_item(nodeid: str, forced_nodeids: Set[str]) -> bool:
546
+ """支持用父级 NodeID(如模块/类)声明的强制收集。"""
547
+ if nodeid in forced_nodeids:
548
+ return True
549
+ for forced in forced_nodeids:
550
+ if nodeid.startswith(forced + "::"):
551
+ return True
552
+ return False
553
+
554
+
465
555
  def _apply_env_check_collection_logic(config, settings: EnvCheckSettings, items: List[pytest.Item]) -> None:
466
- node_map = {item.nodeid: item for item in items}
467
556
  ordered: List[pytest.Item] = []
468
557
  consumed: Set[str] = set()
469
558
  missing_behaviors: List[str] = []
470
559
 
471
- for nodeid in settings.global_nodeids:
472
- item = node_map.get(nodeid)
473
- if not item:
474
- continue
475
- ordered.append(item)
476
- consumed.add(nodeid)
477
- item.stash[ITEM_KIND_KEY] = 'global_check'
478
- item.stash[BEHAVIOR_KEY] = None
560
+ # 1) 全局检查:支持使用模块/类 NodeID 作为前缀声明。
561
+ for prefix in settings.global_nodeids:
562
+ for item in items:
563
+ if item.nodeid in consumed:
564
+ continue
565
+ if item.nodeid == prefix or item.nodeid.startswith(prefix + "::"):
566
+ ordered.append(item)
567
+ consumed.add(item.nodeid)
568
+ item.stash[ITEM_KIND_KEY] = 'global_check'
569
+ item.stash[BEHAVIOR_KEY] = None
479
570
 
571
+ # 2) 特性级检查:同样支持前缀声明,按行为(epic/feature/story)绑定。
480
572
  behavior_checks: Dict[str, pytest.Item] = {}
481
- for nodeid in settings.behavior_nodeids:
482
- item = node_map.get(nodeid)
483
- if not item:
484
- continue
485
- behavior = _ensure_behavior_stashed(item, settings.behavior_scope)
486
- if not behavior:
487
- missing_behaviors.append(nodeid)
488
- continue
489
- if behavior in behavior_checks:
490
- logger.warning(
491
- "特性级检查 %s 重复定义,沿用首次声明的用例 %s",
492
- behavior,
493
- behavior_checks[behavior].nodeid,
494
- )
495
- continue
496
- behavior_checks[behavior] = item
497
- consumed.add(nodeid)
498
- item.stash[ITEM_KIND_KEY] = 'behavior_check'
573
+ for prefix in settings.behavior_nodeids:
574
+ for item in items:
575
+ if item.nodeid in consumed:
576
+ continue
577
+ if item.nodeid != prefix and not item.nodeid.startswith(prefix + "::"):
578
+ continue
579
+ behavior = _ensure_behavior_stashed(item, settings.behavior_scope)
580
+ if not behavior:
581
+ missing_behaviors.append(item.nodeid)
582
+ continue
583
+ if behavior in behavior_checks:
584
+ logger.warning(
585
+ "特性级检查 %s 重复定义,沿用首次声明的用例 %s",
586
+ behavior,
587
+ behavior_checks[behavior].nodeid,
588
+ )
589
+ continue
590
+ behavior_checks[behavior] = item
591
+ consumed.add(item.nodeid)
592
+ item.stash[ITEM_KIND_KEY] = 'behavior_check'
499
593
 
500
594
  if missing_behaviors:
501
595
  logger.warning(
@@ -504,6 +598,7 @@ def _apply_env_check_collection_logic(config, settings: EnvCheckSettings, items:
504
598
  missing_behaviors,
505
599
  )
506
600
 
601
+ # 3) 按业务用例的行为插入对应检查。
507
602
  behavior_inserted: Set[str] = set()
508
603
  for item in items:
509
604
  if item.nodeid in consumed:
@@ -516,10 +611,12 @@ def _apply_env_check_collection_logic(config, settings: EnvCheckSettings, items:
516
611
  behavior_inserted.add(behavior)
517
612
  ordered.append(item)
518
613
 
519
- for behavior, check_item in behavior_checks.items():
520
- if behavior not in behavior_inserted:
521
- ordered.append(check_item)
522
- behavior_inserted.add(behavior)
614
+ # 4) 未匹配到业务用例的特性级检查:force 模式下不执行;auto 模式保持原行为(放到末尾执行)。
615
+ if settings.collect_mode != 'force':
616
+ for behavior, check_item in behavior_checks.items():
617
+ if behavior not in behavior_inserted:
618
+ ordered.append(check_item)
619
+ behavior_inserted.add(behavior)
523
620
 
524
621
  if ordered:
525
622
  items[:] = ordered
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest_platform_adapter
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Pytest集成自动化平台插件
5
5
  Author-email: BlackYau <blackyau426@gmail.com>
6
6
  Maintainer-email: BlackYau <blackyau426@gmail.com>
@@ -87,7 +87,8 @@ pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple pytest-platf
87
87
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
88
88
 
89
89
  ```
90
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
90
+ # 需要把下面的 x.x.x 替换为实际的版本号
91
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
91
92
  ```
92
93
 
93
94
  #### 国内镜像站下载离线安装
@@ -99,7 +100,8 @@ pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
99
100
  然后在命令行中使用以下命令安装(你需要提前安装 `pytest` 和 `allure-pytest`)
100
101
 
101
102
  ```
102
- pip install pytest_platform_adapter-1.1.0-py3-none-any.whl
103
+ # 需要把下面的 x.x.x 替换为实际的版本号
104
+ pip install pytest_platform_adapter-x.x.x-py3-none-any.whl
103
105
  ```
104
106
 
105
107
  ## 使用方法
@@ -193,17 +195,22 @@ platform_env_behavior_checks =
193
195
  tests/env_check/test_function_env_check.py::TestFunctionEnvCheck
194
196
  platform_env_behavior_scope = epic # epic / feature / story
195
197
  platform_env_fail_action = skip # skip / xfail / none
198
+ platform_env_collect_mode = force # force / auto
196
199
  ```
197
200
 
198
201
  - `platform_env_global_checks`:在每次用例执行前跑一遍的检查用例列表。
199
202
  - `platform_env_behavior_checks`:特性级检查用例列表,插件会读取这些用例标签并在同一特性的首个用例前插入执行。
200
203
  - `platform_env_behavior_scope`:定义特性的级别可选的有 epic/feature/story(分别对应 Allure Report 的 behaviors 中的一级目录、二级目录、三级目录)
201
204
  - `platform_env_fail_action`:检查失败后对后续业务用例的处理方式,`skip` 为直接跳过、`xfail` 为继续执行并动态加上 `xfail`(失败记为 XFAIL、通过记为 XPASS)、`none` 仅记录日志不干预执行。
205
+ - `platform_env_collect_mode`:环境检查收集模式,默认 `force`。
206
+ - `force`(强制):即使本次命令行只收集了业务目录,也会强制把 `platform_env_global_checks` / `platform_env_behavior_checks` 声明的 NodeID 注入收集范围;环境检查用例不受 `-m`/`-k` 等筛选影响永远执行;全局检查永远执行;特性级检查仅在本次业务用例中存在同一行为标签(scope 对应 epic/feature/story)的情况下才执行,没有匹配的特性级检查不会执行。
207
+ - `auto`(自动):不额外注入收集参数,仅执行本次 pytest 收集到的检查用例;如果声明的 NodeID 没有被收集到则不会执行。
202
208
 
203
209
  #### 命令行
204
210
 
205
211
  - `--env-check-mode={off,global,behavior,all}`:快速控制启用的检查范围。
206
212
  - `--env-check-scope=<epic|feature|story>`:临时覆盖行为层级设定。
213
+ - `--env-check-collect-mode={force,auto}`:临时覆盖 `platform_env_collect_mode`,控制环境检查的收集/执行策略。
207
214
  - 当 `platform_env_fail_action=xfail` 时,会在受影响的业务用例上自动添加 `pytest.mark.xfail(run=True, strict=False)`,用例依旧执行,只是失败时记为 XFAIL。
208
215
 
209
216
  当检查用例失败时,插件会在 `pytest_runtest_setup` 阶段统一对后续业务用例执行 `skip` 或 `xfail`,并在日志中说明对应的检查节点。检查用例自身依旧遵循 pytest 原生语义,可继续使用 `skip/xfail/flaky` 等标记。