Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

testdata/allure_results/*
testdata/allure_results/*.vscode/
.vscode/
15 changes: 15 additions & 0 deletions pytest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Update file reporting mode in run script
- Refactor reporter implementation to use FileReporter instead of Reporter

### Fixed
- Improve test case collection and execution with better file handling
2 changes: 1 addition & 1 deletion pytest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "testsolar-pytestx"
version = "0.1.56"
version = "0.1.58"
description = "Pytest tool for TestSolar"
authors = [
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},
Expand Down
2 changes: 1 addition & 1 deletion pytest/script/linux/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export PYTHONUNBUFFERED=1
export TESTSOLAR_TTP_LOADINSUBPROC=1 # 隔离环境

/usr/local/bin/testtools_sdk version
/usr/local/bin/testtools_sdk serve --tool pytest
/usr/local/bin/testtools_sdk serve --tool pytest --file-report-mode
10 changes: 5 additions & 5 deletions pytest/src/testsolar_pytestx/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from testsolar_testtool_sdk.model.load import LoadResult, LoadError
from testsolar_testtool_sdk.model.param import EntryParam
from testsolar_testtool_sdk.model.test import TestCase
from testsolar_testtool_sdk.reporter import Reporter
from testsolar_testtool_sdk.reporter import BaseReporter, FileReporter

from .converter import selector_to_pytest, pytest_to_selector, CASE_DRIVE_SEPARATOR
from .filter import filter_invalid_selector_path
Expand All @@ -25,10 +25,10 @@


class PytestCollector:
def __init__(self, pipe_io: Optional[BinaryIO] = None):
def __init__(self, report_file_path: Path):
self.collected: List[Item] = []
self.errors: Dict[str, str] = {}
self.reporter: Reporter = Reporter(pipe_io=pipe_io)
self.reporter: BaseReporter = FileReporter(report_file_path)

def pytest_collection_modifyitems(self, items: Sequence[Union[Item, Collector]]) -> None:
for item in items:
Expand Down Expand Up @@ -105,7 +105,7 @@ def collect_testcases(

testcase_list = [os.path.join(entry_param.ProjectPath, it) for it in pytest_paths if it]

my_plugin = PytestCollector(pipe_io)
my_plugin = PytestCollector(Path(entry_param.FileReportPath))
args = [
f"--rootdir={entry_param.ProjectPath}",
"--collect-only",
Expand Down Expand Up @@ -150,7 +150,7 @@ def collect_testcases(
print(f"[Load] collect testcase count: {len(load_result.Tests)}")
print(f"[Load] collect load error count: {len(load_result.LoadErrors)}")

reporter = Reporter(pipe_io=pipe_io)
reporter = FileReporter(Path(entry_param.FileReportPath))
reporter.report_load_result(load_result)


Expand Down
6 changes: 6 additions & 0 deletions pytest/src/testsolar_pytestx/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def pytest_to_selector(item: Item, project_path: str) -> str:

if hasattr(item, "path") and hasattr(item, "cls") and item.path:
rel_path = os.path.relpath(item.path, project_path)
# 统一使用正斜杠,确保跨平台一致性
rel_path = rel_path.replace(os.sep, "/")
name = item.name
if item.cls:
name = item.cls.__name__ + "/" + name
Expand All @@ -87,6 +89,8 @@ def pytest_to_selector(item: Item, project_path: str) -> str:
full_name = normalize_testcase_name(item.nodeid)
else:
rel_path, _, name = item.location
# 统一使用正斜杠,确保跨平台一致性
rel_path = rel_path.replace(os.sep, "/")
name = name.replace(".", "/")
name = decode_datadrive(name)
full_name = f"{rel_path}?{name}"
Expand Down Expand Up @@ -140,6 +144,8 @@ def normalize_testcase_name(name: str, sub_case_key: Optional[str] = None) -> st
-> test_directory/test_module.py?TestExampleClass/test_example_function/[datedrive]
"""
assert "::" in name
# 统一使用正斜杠,确保跨平台一致性
name = name.replace(os.sep, "/")
name = name.replace("::", "?", 1).replace( # 第一个分割符是文件,因此替换为?
"::", "/"
) # 后续的分割符是测试用例名称,替换为/
Expand Down
9 changes: 5 additions & 4 deletions pytest/src/testsolar_pytestx/executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import sys
from datetime import datetime, timedelta
from typing import BinaryIO, Optional, Dict, Any, List, Callable
Expand All @@ -18,7 +19,7 @@
ResultType,
TestCaseStep,
)
from testsolar_testtool_sdk.reporter import Reporter
from testsolar_testtool_sdk.reporter import BaseReporter, FileReporter
from enum import Enum

from .case_log import gen_logs
Expand Down Expand Up @@ -46,11 +47,11 @@ class RunMode(Enum):
class PytestExecutor:
def __init__(
self,
reporter: Reporter,
reporter: BaseReporter,
comment_fields: Optional[List[str]] = None,
data_drive_key: Optional[str] = None,
) -> None:
self.reporter: Reporter = reporter
self.reporter: BaseReporter = reporter
self.testcase_count = 0
self.testdata: Dict[str, TestResult] = {}
self.skipped_testcase: Dict[str, str] = {}
Expand Down Expand Up @@ -265,7 +266,7 @@ def run_testcases(

append_extra_args(args)

reporter: Reporter = Reporter(pipe_io=pipe_io)
reporter: BaseReporter = FileReporter(report_path=Path(entry.FileReportPath))
exit_code = 0
captured_stderr = ""
if run_mode == RunMode.SINGLE:
Expand Down
2 changes: 1 addition & 1 deletion pytest/src/testsolar_pytestx/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_case_attributes(item: Item, comment_fields: Optional[List[str]] = None
for data_name in mark.args[0]:
if data_name == case_data_name:
attributes["coding_testcase_id"] = mark.args[0][data_name]

attributes["tags"] = json.dumps(tags)
return attributes

Expand Down
Loading
Loading