WebsocketTest 1.0.17__py3-none-any.whl → 1.0.19__py3-none-any.whl

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.
@@ -108,16 +108,14 @@ def install_allure():
108
108
  # os.chmod(os.path.join(ALLURE_BIN_DIR, "allure"), 0o755)
109
109
 
110
110
  # 更新PATH
111
- # if add_to_user_path(ALLURE_BIN_DIR):
112
- # # 立即在当前进程生效
113
- # os.environ["PATH"] = f"{ALLURE_BIN_DIR}{os.pathsep}{os.environ.get('PATH', '')}"
114
-
111
+ add_to_user_path(ALLURE_BIN_DIR)
115
112
  return True
116
113
  except Exception as e:
117
114
  print(f"❌ 安装失败: {type(e).__name__}: {e}", file=sys.stderr)
118
115
  return False
119
116
 
120
117
  def add_to_user_path(path):
118
+ path = os.path.normpath(path) # 规范化路径(去除多余的斜杠)
121
119
  """添加到用户级PATH环境变量"""
122
120
  try:
123
121
  if sys.platform == "win32":
@@ -129,22 +127,22 @@ def add_to_user_path(path):
129
127
  winreg.KEY_READ | winreg.KEY_WRITE,
130
128
  ) as key:
131
129
  current_path, _ = winreg.QueryValueEx(key, "Path")
132
-
133
130
  if path in current_path.split(os.pathsep):
131
+ print(f"⏩ path中路径已存在: {path}")
134
132
  return False
135
133
 
136
134
  new_path = f"{current_path}{os.pathsep}{path}" if current_path else path
137
135
  winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
138
-
139
- # 刷新环境变量
136
+ # 刷新时只更新用户 PATH,不携带系统 PATH
140
137
  subprocess.run(
141
- 'powershell -command "[Environment]::SetEnvironmentVariable(\'Path\', $env:Path + \';{}\', \'User\')"'
142
- .format(path),
138
+ f'powershell -command "[Environment]::SetEnvironmentVariable(\'Path\', \'{new_path}\', \'User\')"',
143
139
  shell=True,
144
140
  check=True
145
141
  )
146
142
  print(f"✅ 已添加PATH: {path}")
147
143
  return True
144
+ except PermissionError:
145
+ print("❌ 需要管理员权限!")
148
146
  except Exception as e:
149
147
  print(f"⚠️ 添加PATH失败: {e}\n请手动添加 {path} 到环境变量", file=sys.stderr)
150
148
  return False
@@ -7,7 +7,6 @@ from pathlib import Path
7
7
  from WebsocketTest.common.Assertion import Assert
8
8
  import pytest
9
9
  import traceback
10
- from WebsocketTest.conftest import SHEET_NAME
11
10
  class WSBaseApi:
12
11
  def __init__(self, **kwargs):
13
12
  self.request = {}
@@ -51,7 +50,7 @@ class BaseApiTest:
51
50
  "请检查模块路径和类命名是否符合规范"
52
51
  ) from e
53
52
 
54
-
53
+ SHEET_NAME = f"{os.getenv('PROJECT')}-{os.getenv('SERVICE')}"
55
54
  @pytest.mark.parametrize('case_suite', gen_case_suite(CASE_PATH,sheet_name=SHEET_NAME))
56
55
  def test(self, case_suite, setup_env):
57
56
  """测试用例执行模板"""
WebsocketTest/conftest.py CHANGED
@@ -2,9 +2,6 @@ import pytest
2
2
  import yaml
3
3
  from pathlib import Path
4
4
 
5
- SHEET_NAME = "0" # 默认值
6
-
7
-
8
5
  # 设置环境信息的 fixture
9
6
  @pytest.fixture(scope="session")
10
7
  def setup_env(request):
@@ -59,11 +56,4 @@ def pytest_addoption(parser):
59
56
  default="vwa",
60
57
  help="Project name is required"
61
58
  )
62
-
63
- def pytest_configure(config):
64
- project = config.getoption("--project")
65
- service = config.getoption("--service")
66
- """在测试初始化阶段解析参数并全局缓存"""
67
- global SHEET_NAME
68
- SHEET_NAME = f"{project}-{service}"
69
59
 
@@ -1,4 +1,4 @@
1
- import subprocess
1
+ import subprocess,pytest
2
2
  import argparse
3
3
  import shutil
4
4
  import time
@@ -72,27 +72,27 @@ class TestRunner:
72
72
 
73
73
  def run_pytest_tests(self) -> bool:
74
74
  """执行pytest测试"""
75
- # 构建基础命令列表
75
+ # # 构建基础命令列表
76
76
  cmd = [
77
- "pytest",
78
77
  "-m", self.args.service.split('_')[0],
79
78
  "--env", self.args.env,
80
79
  "--app", self.args.app,
81
80
  "--service", self.args.service,
82
81
  "--project", self.args.project,
83
82
  "--alluredir", self.allure_results
84
- ,"testcase\\test_all.py"
85
83
  ]
86
84
  # 添加可选测试路径(如果存在)
87
85
  if hasattr(self.args, 'testcase') and self.args.testcase:
88
- cmd.insert(1, self.args.testcase)
86
+ cmd.insert(0, self.args.testcase)
89
87
  try:
90
88
  # logger.info(f"run_pytest_tests Executing: {' '.join(cmd)}")
91
- subprocess.run(cmd, check=True, timeout=3600)
92
- except subprocess.CalledProcessError as e:
93
- logger.error(f"Tests failed with exit code {e.returncode}")
94
- except subprocess.TimeoutExpired:
95
- logger.error("Test execution timed out after 1 hour")
89
+ import os
90
+ os.environ["PROJECT"] = self.args.project
91
+ os.environ["SERVICE"] = self.args.service
92
+ # 调用 pytest
93
+ pytest.main(cmd)
94
+ except Exception as e:
95
+ logger.error(f"Test execution failed: {e}")
96
96
 
97
97
  def generate_allure_report(self) -> bool:
98
98
  """生成Allure报告"""
@@ -0,0 +1,85 @@
1
+ # WebSocket 接口自动化测试工具 (WebSocketTest)
2
+
3
+ #### 介绍
4
+
5
+ 这是一个基于 WebSocket 协议的接口自动化测试工具。它可以用于自动化测试 WebSocket 接口,确保接口的稳定性和可靠性。
6
+
7
+ #### 系统要求
8
+
9
+ **Python 3.10+**:确保你的系统上已经安装了 Python 3.10(推荐使用最新稳定版)。
10
+
11
+
12
+ #### 安装步骤
13
+
14
+ **1.安装 Python:**
15
+ 确保你的系统上已经安装了 Python 3.10 或更高版本。你可以从 [Python 官方网站 ](https://www.python.org/downloads/?spm=5176.28103460.0.0.40f75d27PnqPkU)下载并安装。
16
+ **2.安装 WebSocketTest 工具:**
17
+
18
+ ```
19
+ pip install WebsocketTest
20
+ ```
21
+
22
+ **3.安装allure 工具:**
23
+ ```
24
+ install-allure
25
+ <!-- 注:allure安装完,会自动配置环境变量,需要重启终端才能生效 -->
26
+ ```
27
+ **4.创建测试项目:**
28
+ ```
29
+ <!-- 一次性操作,yourtestProject创建成功以后,测试直接cd到yourtestProject下,进行ws test -->
30
+ ws startproject yourtestProject
31
+ cd yourtestProject
32
+ ```
33
+
34
+ **5.运行测试:**
35
+ 在命令行中运行以下命令:
36
+
37
+ ```
38
+ <!-- 安徽5.0链路aqua测试: -->
39
+ ws test --env uat --app 0f0826ab --service aqua --project vwa
40
+ ws test --env live --app 0f0826ab --service aqua --project vwa
41
+ <!-- 安徽5.4链路sds_gateway测试: -->
42
+ ws test --env uat --app 3d7d3ea4 --service gateway_5.4 --project vwa
43
+ ws test --env live --app 3d7d3ea4 --service gateway_5.4 --project vwa
44
+ <!-- 安徽5.0链路sds_gateway测试: -->
45
+ ws test --env uat --app 0f0826ab --service gateway_5.0 --project vwa
46
+ ws test --env live --app 0f0826ab --service gateway_5.0 --project vwa
47
+ <!-- 奥迪aqua测试: -->
48
+ ws test --env uat --app 576d9f07 --service aqua --project svm
49
+ ws test --env live --app 576d9f07 --service aqua --project svm
50
+ <!-- 上汽5.0链路sds_gateway测试: -->
51
+ ws test --env uat --app 66ba7ded --service gateway_5.0 --project svw
52
+ ws test --env live --app 66ba7ded --service gateway_5.0 --project svw
53
+
54
+ <!-- 指定Gatewaycase -->
55
+ ws test --env uat --app 3d7d3ea4 --service gateway_5.4 --project vwa --testcase testcase/test_all.py::TestGateway::test[case_suite0]
56
+ <!-- 指定Aquacase -->
57
+ ws test --env uat --app 0f0826ab --service aqua --project vwa --testcase testcase/test_all.py::TestAqua::test[case_suite0]
58
+ ```
59
+
60
+ #### 其他
61
+ ```
62
+ <!-- 本地开发模式调试 -->
63
+ pip install -e .
64
+
65
+ <!-- 打包 -->
66
+ python setup.py sdist bdist_wheel
67
+ <!-- 上传 -->
68
+ twine upload --repository pypi setup_temp/dist/*
69
+ <!-- 卸载 -->
70
+ pip uninstall WebsocketTest
71
+ <!-- 安装 -->
72
+ pip install WebsocketTest==1.0.14
73
+
74
+ <!-- 关闭allure进程 -->
75
+ netstat -ano | findstr "8883"
76
+ taskkill /F /PID xxID
77
+
78
+ <!-- 安装虚拟环境 -->
79
+ python -m venv venv
80
+ <!-- 激活venv虚拟环境 -->
81
+ Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
82
+ .\venv\Scripts\Activate.ps1
83
+ <!-- 退出venv -->
84
+ deactivate
85
+ ```
@@ -30,7 +30,6 @@ def setup_env(request):
30
30
  'service': service,
31
31
  'project': project})
32
32
  return environments
33
-
34
33
  # 添加命令行选项
35
34
  def pytest_addoption(parser):
36
35
  parser.addoption(
@@ -57,7 +56,4 @@ def pytest_addoption(parser):
57
56
  default="vwa",
58
57
  help="Project name is required"
59
58
  )
60
-
61
-
62
-
63
-
59
+
@@ -1,9 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: WebsocketTest
3
- Version: 1.0.17
3
+ Version: 1.0.19
4
4
  Summary: websocket api autotest
5
- Requires-Dist: allure_python_commons==2.13.5
6
- Requires-Dist: numpy==2.2.4
5
+ Requires-Dist: allure-pytest==2.13.5
7
6
  Requires-Dist: pandas==2.2.3
8
7
  Requires-Dist: pytest==8.2.2
9
8
  Requires-Dist: PyYAML==6.0.2
@@ -1,8 +1,8 @@
1
1
  WebsocketTest/__init__.py,sha256=u71SAVmbgsyp0K21kilo7pIDgeyxsaHAi93clC0OIPQ,556
2
- WebsocketTest/allure_installer.py,sha256=mqcEZQsVnqMHtkH_gdiKD4ibo49u7NpLqvME1rvxBtk,6819
2
+ WebsocketTest/allure_installer.py,sha256=q6d3dIJVeL6gFCyqVUAAIwtmDVuM2cFgOzEAU2BfCSY,6852
3
3
  WebsocketTest/cli.py,sha256=HcnjgRLM404fVszrSRAf7G1y9XLJ_ZetVtRIwavS4xE,987
4
- WebsocketTest/conftest.py,sha256=ZEbTt7J--BEhCPnT30LhWS33vQr8HPEM3ZfwgoKj2fM,2164
5
- WebsocketTest/run_tests.py,sha256=U-53f2y5rYFbs98QGheuZkvQPqCVPF6UZKk5812i3cE,6128
4
+ WebsocketTest/conftest.py,sha256=qFAgwWwi2_MjmN6LMlj_zk3XADcYqp2cr5t8qxYHF1g,1879
5
+ WebsocketTest/run_tests.py,sha256=ippnfovdOn1vDxNWXMZTUsWYdT--4eAtfubv9qgsIRY,6063
6
6
  WebsocketTest/caseScript/Aqua.py,sha256=dTjVd4FPka5lMUvxa1DsGTJ6gx7NRo5NGNunrue3d0M,7439
7
7
  WebsocketTest/caseScript/Gateway.py,sha256=4_BlJPbn6X_eFHYz2orn3fXPQMPz5jRdUlj6tXkeX2Q,11748
8
8
  WebsocketTest/caseScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -10,17 +10,16 @@ WebsocketTest/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
10
10
  WebsocketTest/commands/startproject.py,sha256=xTL6Tct8J8Ks6QD2VrQkNAWGhyv1UEMBuh2gmKCi3d0,909
11
11
  WebsocketTest/commands/test.py,sha256=16i5SI9_kfR67bGWR13Id6HUr4qvYalz4WcNSdvS4Mo,893
12
12
  WebsocketTest/common/Assertion.py,sha256=Kd86Dr6CkPGHN4747T4doyZjklhEFaQ14WCJxuN59IU,5229
13
- WebsocketTest/common/WSBaseApi.py,sha256=8lfmUsg5Foavo7FCvJzNhXBTVHO0wvpjkWn1swzdszg,4131
13
+ WebsocketTest/common/WSBaseApi.py,sha256=8ErG6EeQrF-lw0TS0rRyEYp_-De1ZA--WgJ0TbvUuIw,4149
14
14
  WebsocketTest/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  WebsocketTest/common/assertUtils.py,sha256=poyL6J_WXb2BJvaABCILfiWHN7gHSTRcMWvpjk224yU,4713
16
16
  WebsocketTest/common/logger.py,sha256=JY7dJLVObKoA6E-5FJ0EMX_EyN8Otg4_4FYywKVSkcg,367
17
- WebsocketTest/common/test.py,sha256=KjKL3vMQGuYsWiSmYqw2ypApUtGHBlG_6Sy1QpVkEJ4,1110
18
17
  WebsocketTest/common/utils.py,sha256=29aylauHjrKrJ40PZAcgmikA7U9RJ_qQiX2vjIxsdnA,8748
19
18
  WebsocketTest/libs/allure-2.30.0.zip,sha256=SEc2gYElQbTQrIcpJ5gLIWptfPW8kPITU8gs4wezZho,26551281
20
- WebsocketTest/templates/basic/conftest.py,sha256=y2_2961mhCYSRMp5X9xLq3nOmRzaTSgD3GDdrlTqxn4,1885
19
+ WebsocketTest/templates/basic/README.md,sha256=3YJSUPSTxTYmJrUHvyCjFivK8XD-5FgvVainTVRdiaI,2927
20
+ WebsocketTest/templates/basic/conftest.py,sha256=qFAgwWwi2_MjmN6LMlj_zk3XADcYqp2cr5t8qxYHF1g,1879
21
21
  WebsocketTest/templates/basic/pytest.ini,sha256=An32MB2Yy2L4EVP9WoczW8x0ISAXsgG0tlSLta-cDcs,589
22
- WebsocketTest/templates/basic/执行命令.txt,sha256=0Ocitul_eNgwkqryGA_ozPfyb5b8XlTIP2TMOgl7CaA,1650
23
- WebsocketTest/templates/basic/__pycache__/conftest.cpython-310-pytest-8.2.2.pyc,sha256=q2WJ_-drfCQS8zyAbemBYHaroAHA8-40KoeO2ohwV5c,1495
22
+ WebsocketTest/templates/basic/__pycache__/conftest.cpython-310-pytest-8.2.2.pyc,sha256=6XLNaJ6_0w_6zXPawybQR8yT1svXwLKlZehtjDtvm_A,1495
24
23
  WebsocketTest/templates/basic/config/svw/live.yml,sha256=dqTMDubVYO0lt2kPoHgbZW0ZVMaLO7-OjfBmHedqJuU,31
25
24
  WebsocketTest/templates/basic/config/svw/uat.yml,sha256=DX8Bn_iL5JdFHxHSo1QdRHZLC0C6pId84dit2nutkqM,30
26
25
  WebsocketTest/templates/basic/config/svw/aqua/uat.yml,sha256=Kn5vnsCVWaLuJA2m97EYy3ZN123H66-z2XSxAzgO97Q,358
@@ -85,8 +84,8 @@ WebsocketTest/templates/basic/testcase/__pycache__/test_gateway.cpython-310-pyte
85
84
  WebsocketTest/templates/basic/testcase/__pycache__/test_gateway1.cpython-310-pytest-8.2.2.pyc,sha256=9_jiZtyNwQfXe-Jz1acHxrwz5snYfBngqgTFtIWhRNA,5684
86
85
  WebsocketTest/templates/basic/testcase/__pycache__/test_gatewaybak.cpython-310-pytest-8.2.2.pyc,sha256=L50gNeQvSuFq2e-arnmKqYJR75ZrThiVaiIow5UUTjo,5587
87
86
  WebsocketTest/templates/basic/testcase/__pycache__/test_limin.cpython-310-pytest-8.2.2.pyc,sha256=hx7j0GNxlgTscC36dUBHeo401Mo3bRt1cq6t7e7dDSA,3434
88
- websockettest-1.0.17.dist-info/METADATA,sha256=Fz8bn4cCgTKszTPIunMV24FerZbexid_x6ACtBc0XcA,334
89
- websockettest-1.0.17.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
90
- websockettest-1.0.17.dist-info/entry_points.txt,sha256=r5FtB9A16mLy9v8B77rzZOxgn63ao8z4FTyvJ2KS3jo,108
91
- websockettest-1.0.17.dist-info/top_level.txt,sha256=2iF1gZSbXLjVFOe5ZKQiCLC1FzAwhcQUM88yGi-vrCU,14
92
- websockettest-1.0.17.dist-info/RECORD,,
87
+ websockettest-1.0.19.dist-info/METADATA,sha256=AvFUAKdICFII19SlBtfruhnbxwRZFy6BSua7SKfxQ98,297
88
+ websockettest-1.0.19.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
89
+ websockettest-1.0.19.dist-info/entry_points.txt,sha256=r5FtB9A16mLy9v8B77rzZOxgn63ao8z4FTyvJ2KS3jo,108
90
+ websockettest-1.0.19.dist-info/top_level.txt,sha256=2iF1gZSbXLjVFOe5ZKQiCLC1FzAwhcQUM88yGi-vrCU,14
91
+ websockettest-1.0.19.dist-info/RECORD,,
@@ -1,36 +0,0 @@
1
- import websockets
2
- from functools import cached_property
3
- import asyncio
4
- from WebsocketTest.common.utils import *
5
- import allure
6
- from pathlib import Path
7
- from WebsocketTest.common.Assertion import Assert
8
- import pytest
9
- import traceback
10
-
11
-
12
- CASE_PATH = Path.cwd().resolve().joinpath("data/case_data.xlsx")
13
- @pytest.fixture
14
- def sheet_name(request):
15
- """动态获取 sheet_name"""
16
- service = request.config.getoption("--service")
17
- project = request.config.getoption("--project")
18
- return f"{project}_{service}"
19
-
20
- @pytest.fixture
21
- def case_suite(sheet_name):
22
- """生成测试数据"""
23
- return gen_case_suite(CASE_PATH, sheet_name)
24
-
25
- class BaseApiTest:
26
- def test(self, case_suite, setup_env):
27
- """测试用例执行模板"""
28
- try:
29
- params = merge_dicts(case_suite, setup_env)
30
- runner = self.API_TEST_RUNNER_CLASS(**params)
31
- runner.run()
32
- self._record_allure_report(runner)
33
- self._execute_assertions(runner, case_suite)
34
- except Exception as e:
35
- self._record_error(e)
36
- raise
@@ -1,47 +0,0 @@
1
-
2
- 安徽5.0链路aqua测试:
3
- ws test --env uat --app 0f0826ab --service aqua --project vwa
4
- ws test --env live --app 0f0826ab --service aqua --project vwa
5
- 安徽5.4链路sds_gateway测试:
6
- ws test --env uat --app 3d7d3ea4 --service gateway_5.4 --project vwa
7
- ws test --env live --app 3d7d3ea4 --service gateway_5.4 --project vwa
8
- 安徽5.0链路sds_gateway测试:
9
- ws test --env uat --app 0f0826ab --service gateway_5.0 --project vwa
10
- ws test --env live --app 0f0826ab --service gateway_5.0 --project vwa
11
- 奥迪aqua测试:
12
- ws test --env uat --app 576d9f07 --service aqua --project svm
13
- ws test --env live --app 576d9f07 --service aqua --project svm
14
- 上汽5.0链路sds_gateway测试:
15
- ws test --env uat --app 66ba7ded --service gateway_5.0 --project svw
16
- ws test --env live --app 66ba7ded --service gateway_5.0 --project svw
17
-
18
- ws startproject d
19
- python run_tests.py --env live --app 0f0826ab --service gateway_5.0 --project vwa
20
- pip install -e .
21
- 指定Gatewaycase
22
- ws test --env uat --app 3d7d3ea4 --service gateway_5.4 --project vwa --testcase testcase/test_all.py::TestGateway::test[case_suite0]
23
- 指定Aquacase
24
- testcase/test_all.py::TestAqua::test[case_suite0]
25
-
26
- 关闭allure进程
27
- netstat -ano | findstr "8883"
28
- taskkill /F /PID 25804
29
-
30
- 打包
31
- python setup.py sdist bdist_wheel
32
- 上传
33
- twine upload --repository pypi setup_temp/dist/*
34
- 卸载
35
- pip uninstall WebsocketTest
36
- 安装
37
- pip install WebsocketTest==1.0.14
38
-
39
-
40
-
41
- 安装虚拟环境
42
- python -m venv venv
43
- 激活venv虚拟环境
44
- Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
45
- .\venv\Scripts\Activate.ps1
46
- 退出venv
47
- deactivate