Skip to content

Commit cffcbf6

Browse files
authored
Add user custom args when load case (#76)
* 加载用例时也传递用户额外参数,用于避免一些特殊的插件,强制要求输入参数 * bump version * add more comments
1 parent 1614bec commit cffcbf6

5 files changed

Lines changed: 20 additions & 9 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.27"
3+
version = "0.1.28"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/collector.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .converter import selector_to_pytest, pytest_to_selector, CASE_DRIVE_SEPARATOR
2121
from .filter import filter_invalid_selector_path
2222
from .parser import parse_case_attributes
23+
from .util import append_extra_args
2324

2425

2526
def collect_testcases(
@@ -68,6 +69,8 @@ def collect_testcases(
6869
"--continue-on-collection-errors",
6970
"-v",
7071
]
72+
append_extra_args(args)
73+
7174
args.extend(testcase_list)
7275

7376
print(f"[Load] try to collect testcases: {args}")

‎pytest/src/testsolar_pytestx/executor.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import BinaryIO, Optional, Dict, Any, List, Callable
55

66
import pytest
7-
import shlex
87
from loguru import logger
98
from pytest import Item, Session
109

@@ -26,6 +25,7 @@
2625
initialization_allure_dir,
2726
generate_allure_results,
2827
)
28+
from .util import append_extra_args
2929
from .filter import filter_invalid_selector_path
3030
from .parser import parse_case_attributes
3131

@@ -106,12 +106,6 @@ def run_testcases(
106106
logger.info("pytest process exit")
107107

108108

109-
def append_extra_args(args: List[str]) -> None:
110-
extra_args = os.environ.get("TESTSOLAR_TTP_EXTRAARGS", "")
111-
if extra_args:
112-
args.extend(shlex.split(extra_args))
113-
114-
115109
class PytestExecutor:
116110
def __init__(
117111
self,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import shlex
3+
from typing import List
4+
5+
6+
def append_extra_args(args: List[str]) -> None:
7+
"""
8+
将用户配置的额外参数作为命令行数组传递给pytest
9+
10+
注意用户配置的字符串中可能存在空格类型参数,比如 -m "not m3",因此需要使用shlex.split来分割参数
11+
"""
12+
extra_args = os.environ.get("TESTSOLAR_TTP_EXTRAARGS", "")
13+
if extra_args:
14+
args.extend(shlex.split(extra_args))

‎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.27'
5+
version: '0.1.28'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

0 commit comments

Comments
 (0)