Skip to content

Commit 4b8b8de

Browse files
New performance testing tools
New performance testing tools New performance testing tools
1 parent 06442f0 commit 4b8b8de

24 files changed

+2515
-971
lines changed

test/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
reports/
2+
dataset/
3+
logs/
4+
$null
5+
*__pycache__/
6+
.*
7+
*.log
8+
start.bat
9+
!.gitignore

test/README.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# UCM Pytest Testing Framework
2+
3+
A unified cache management testing framework based on pytest, supporting multi-level testing, flexible marking, performance data collection, and beautiful Allure report generation.
4+
5+
## Framework Features
6+
7+
- [x] 🏗️ **Multi-level Testing**: UnitTest(0) → Smoke(1) → Feature(2) → E2E(3)
8+
- [x] 🏷️ **Flexible Marking**: Support for feature tags, platform tags, and reliability tags
9+
- [x] 📊 **Data Collection**: Integrated InfluxDB performance data pushing
10+
- [x] 📋 **Beautiful Reports**: Allure test report integration, supporting both static HTML and dynamic server modes
11+
- [x] 🔧 **Configuration Management**: Flexible YAML-based configuration system
12+
- [x] 🚀 **Automation**: Support for parallel test execution and automatic cleanup
13+
14+
## Test Level Definitions
15+
16+
| Level | Name | Description | Execution Time |
17+
|-----|------|------|----------|
18+
| 0 | UnitTest | Unit Tests | Every code commit |
19+
| 1 | Smoke | Smoke Tests | Build verification |
20+
| 2 | Feature | Feature Tests | When features are completed |
21+
| 3 | E2E | End-to-End Tests | Before version release |
22+
23+
## Directory Structure
24+
25+
```
26+
test/
27+
├── config.yaml # Test framework configuration file
28+
├── conftest.py # pytest configuration and fixtures, main program entry
29+
├── pytest.ini # pytest markers and basic configuration
30+
├── requirements.txt # Dependency package list
31+
├── common/ # Common utility library
32+
│ ├── __init__.py
33+
│ ├── config_utils.py # Configuration file reading tools
34+
│ ├── influxdb_utils.py # InfluxDB writing tools
35+
│ └── allure_utils.py # Allure reporting tools
36+
├── suites/ # Test case directory
37+
│ ├── UnitTest/ # Unit tests (stage 0)
38+
│ ├── Smoke/ # Smoke tests (stage 1)
39+
│ ├── Feature/ # Feature tests (stage 2)
40+
│ ├── E2E/ # End-to-end tests (stage 3)
41+
│ └── test_demo_function.py# Example test cases
42+
├── reports/ # Test report directory
43+
└── logs/ # Test log directory
44+
```
45+
46+
## Quick Start
47+
48+
### 1. Environment Setup
49+
```bash
50+
# Install dependencies
51+
pip install -r requirements.txt
52+
53+
# Ensure Allure CLI is installed (for report generation)
54+
# Download from: https://github.com/allure-framework/allure2/releases
55+
```
56+
57+
### 2. Configuration File
58+
The main configuration file is `config.yaml`, containing the following configuration items:
59+
- **reports**: Report generation configuration (HTML/Allure)
60+
- **log**: Logging configuration
61+
- **influxdb**: Performance data push configuration
62+
- **llm_connection**: LLM connection configuration
63+
64+
### 3. Running Tests
65+
```bash
66+
# Run all tests
67+
pytest
68+
69+
# Run specific level tests
70+
pytest --stage=1 # Run smoke tests
71+
pytest --stage=2+ # Run feature and end-to-end tests
72+
73+
# Run specific tag tests
74+
pytest --feature=performance # Run performance-related tests
75+
pytest --platform=gpu # Run GPU platform tests
76+
pytest --reliability=high # Run high reliability tests
77+
78+
# Combined filtering
79+
pytest --stage=1 --feature=performance,accuracy # Performance and accuracy tests in smoke tests
80+
```
81+
82+
## Test Case Standards
83+
84+
### Basic Structure
85+
```python
86+
import pytest
87+
import allure
88+
from common.config_utils import config_utils as config_instance
89+
90+
class TestExample:
91+
"""Test example class"""
92+
93+
@pytest.mark.stage(2)
94+
@pytest.mark.feature("performance")
95+
@pytest.mark.platform("gpu")
96+
def test_gpu_performance(self):
97+
"""Test GPU performance"""
98+
# Arrange
99+
test_data = config_instance.get_config("test_data")
100+
101+
# Act & Assert
102+
with allure.step("Execute GPU computation"):
103+
result = perform_gpu_calculation(test_data)
104+
assert result.is_valid
105+
106+
# Collect performance data
107+
from common.influxdb_utils import push_to_influx
108+
push_to_influx("gpu_compute_time", result.duration, {
109+
"test_name": "test_gpu_performance",
110+
"platform": "gpu"
111+
})
112+
```
113+
114+
### Marking Usage Guidelines
115+
116+
#### 1. Level Markers (Required)
117+
```python
118+
@pytest.mark.stage(0) # Unit tests
119+
@pytest.mark.stage(1) # Smoke tests
120+
@pytest.mark.stage(2) # Feature tests
121+
@pytest.mark.stage(3) # End-to-end tests
122+
```
123+
124+
#### 2. Feature Markers (Recommended)
125+
```python
126+
@pytest.mark.feature("performance") # Performance tests
127+
@pytest.mark.feature("accuracy") # Accuracy tests
128+
@pytest.mark.feature("memory") # Memory tests
129+
```
130+
131+
#### 3. Platform Markers (Optional)
132+
```python
133+
@pytest.mark.platform("gpu") # GPU platform tests
134+
@pytest.mark.platform("npu") # NPU platform tests
135+
@pytest.mark.platform("cpu") # CPU platform tests
136+
```
137+
138+
#### 4. Reliability Markers (Optional)
139+
```python
140+
@pytest.mark.reliability("high") # High reliability tests
141+
@pytest.mark.reliability("medium") # Medium reliability tests
142+
@pytest.mark.reliability("low") # Low reliability tests
143+
```
144+
145+
## Allure Report Integration
146+
147+
### 1. Basic Usage
148+
```python
149+
import allure
150+
151+
@allure.feature('User Authentication')
152+
@allure.story('Login Function')
153+
def test_user_login():
154+
"""Test user login functionality"""
155+
with allure.step("Enter username and password"):
156+
login_page.enter_credentials("user", "pass")
157+
158+
with allure.step("Click login button"):
159+
login_page.click_login()
160+
161+
with allure.step("Verify successful login"):
162+
assert dashboard_page.is_displayed()
163+
164+
# Add attachment
165+
allure.attach("Screenshot data", name="Login Screenshot",
166+
attachment_type=allure.attachment_type.PNG)
167+
```
168+
169+
### 2. Report Configuration
170+
Configure Allure reports in `config.yaml`:
171+
```yaml
172+
reports:
173+
allure:
174+
enabled: true
175+
html_enable: true
176+
serve_mode: true # Use dynamic server mode
177+
serve_host: "localhost"
178+
serve_port: 8081
179+
directory: "allure-results"
180+
```
181+
182+
### 3. Report Viewing
183+
- **Static HTML Mode**: Automatically generates static HTML reports after test completion
184+
- **Dynamic Server Mode**: Starts Allure server, providing interactive report interface
185+
186+
## Performance Data Collection
187+
188+
### InfluxDB Integration
189+
```python
190+
from common.influxdb_utils import push_to_influx
191+
192+
# Collect performance data in tests
193+
def test_performance_metrics():
194+
start_time = time.time()
195+
196+
# Execute test logic
197+
result = perform_operation()
198+
199+
# Push performance data to InfluxDB
200+
push_to_influx("operation_duration", time.time() - start_time, {
201+
"test_name": "test_performance_metrics",
202+
"operation_type": "calculation",
203+
"success": str(result.success)
204+
})
205+
```
206+
207+
## Extensions and Customization
208+
209+
### Adding New Markers
210+
1. Add new marker definitions in the `markers` section of `pytest.ini`
211+
2. Keep the `markers =` and `# end of markers` lines unchanged
212+
3. Re-run tests to use new markers
213+
214+
### Custom Configuration
215+
Customize through `config.yaml`:
216+
- Report format and storage location
217+
- Log level and output format
218+
- InfluxDB connection parameters
219+
- LLM service configuration

0 commit comments

Comments
 (0)