0
# Test Filtering
1
2
Filter and select tests for execution based on Allure labels, metadata, and test plans. This enables targeted test runs and organized test execution strategies.
3
4
## Capabilities
5
6
### Severity-Based Filtering
7
8
Filter tests by severity levels to run only tests of specific importance or priority.
9
10
```python { .api }
11
--allure-severities SEVERITIES_SET
12
"""
13
Run tests that have at least one of the specified severity labels.
14
15
Parameters:
16
- SEVERITIES_SET: Comma-separated list of severity names
17
18
Valid severity values:
19
- blocker: Highest priority, blocks major functionality
20
- critical: High priority, affects core features
21
- normal: Standard priority (default if no severity specified)
22
- minor: Low priority, minor issues
23
- trivial: Lowest priority, cosmetic issues
24
25
Usage:
26
pytest --allure-severities blocker,critical tests/
27
"""
28
```
29
30
### BDD-Style Filtering
31
32
Filter tests using Behavior-Driven Development labels for organizing tests by epics, features, and stories.
33
34
```python { .api }
35
--allure-epics EPICS_SET
36
"""
37
Run tests that have at least one of the specified epic labels.
38
39
Parameters:
40
- EPICS_SET: Comma-separated list of epic names
41
42
Usage:
43
pytest --allure-epics "User Management,Payment Processing" tests/
44
"""
45
46
--allure-features FEATURES_SET
47
"""
48
Run tests that have at least one of the specified feature labels.
49
50
Parameters:
51
- FEATURES_SET: Comma-separated list of feature names
52
53
Usage:
54
pytest --allure-features "Login,Registration,Password Reset" tests/
55
"""
56
57
--allure-stories STORIES_SET
58
"""
59
Run tests that have at least one of the specified story labels.
60
61
Parameters:
62
- STORIES_SET: Comma-separated list of story names
63
64
Usage:
65
pytest --allure-stories "User can login,User can logout" tests/
66
"""
67
```
68
69
### ID-Based Filtering
70
71
Filter tests by test case IDs for running specific test cases or test subsets.
72
73
```python { .api }
74
--allure-ids IDS_SET
75
"""
76
Run tests that have at least one of the specified ID labels.
77
78
Parameters:
79
- IDS_SET: Comma-separated list of test IDs
80
81
Usage:
82
pytest --allure-ids TC001,TC002,TC005 tests/
83
"""
84
```
85
86
### Custom Label Filtering
87
88
Filter tests by custom labels for flexible test organization and selection strategies.
89
90
```python { .api }
91
--allure-label LABEL_NAME=values
92
"""
93
Run tests that have at least one of the specified labels.
94
95
Parameters:
96
- LABEL_NAME: Name of the custom label type
97
- values: Comma-separated list of label values
98
99
Can be specified multiple times for different label types.
100
101
Usage:
102
pytest --allure-label component=auth,payments --allure-label priority=P1 tests/
103
"""
104
```
105
106
## Usage Examples
107
108
### Single Criterion Filtering
109
110
```bash
111
# Run only critical and blocker tests
112
pytest --allure-severities critical,blocker tests/
113
114
# Run tests for specific features
115
pytest --allure-features "User Authentication,Profile Management" tests/
116
117
# Run specific test cases by ID
118
pytest --allure-ids TC001,TC002,TC003 tests/
119
```
120
121
### Multi-Criteria Filtering
122
123
```bash
124
# Combine multiple filter types (AND logic within types, OR logic between types)
125
pytest \
126
--allure-severities critical,blocker \
127
--allure-features "Payment Processing" \
128
--allure-label component=backend \
129
tests/
130
131
# Custom labels for complex filtering
132
pytest \
133
--allure-label priority=P1,P2 \
134
--allure-label team=auth \
135
--allure-label environment=staging \
136
tests/
137
```
138
139
### BDD Workflow Example
140
141
```bash
142
# Epic-level testing
143
pytest --allure-epics "E-commerce Platform" tests/
144
145
# Feature development cycle
146
pytest --allure-features "Shopping Cart,Checkout Process" tests/
147
148
# Story-level validation
149
pytest --allure-stories "User can add items to cart,User can remove items from cart" tests/
150
```
151
152
## Label Assignment in Tests
153
154
Tests must have appropriate labels assigned to be selected by filters:
155
156
```python
157
import pytest
158
import allure
159
160
# Using allure decorators
161
@allure.severity(allure.severity_level.CRITICAL)
162
@allure.epic("User Management")
163
@allure.feature("Authentication")
164
@allure.story("User Login")
165
@allure.testcase("TC001")
166
def test_user_login():
167
pass
168
169
# Using pytest markers
170
@pytest.mark.allure_label(label_type="severity", "critical")
171
@pytest.mark.allure_label(label_type="component", "auth")
172
@pytest.mark.allure_label(label_type="priority", "P1")
173
def test_password_reset():
174
pass
175
```
176
177
## Filter Logic
178
179
- **Within label type**: OR logic (test matches if it has ANY of the specified values)
180
- **Between label types**: AND logic (test must match ALL specified label types)
181
- **Default severity**: Tests without severity labels are treated as "normal" severity
182
- **Missing labels**: Tests without a required label type are excluded from results