or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

formatter.mdhooks.mdindex.mdlistener.mdutils.md

listener.mddocs/

0

# Event Processing

1

2

The AllureListener class handles the core test execution event processing, converting Behave's test lifecycle events into Allure report data. It manages test sessions, scenarios, steps, and attachments.

3

4

## Capabilities

5

6

### AllureListener Class

7

8

Core event processor that implements the allure_commons hook interface to capture and convert Behave test execution events into Allure report format.

9

10

```python { .api }

11

class AllureListener:

12

def __init__(self, behave_config):

13

"""

14

Initialize the Allure listener with Behave configuration.

15

16

Parameters:

17

- behave_config: Behave configuration object containing test settings

18

and userdata for Allure configuration options

19

20

Attributes:

21

- issue_pattern (str): Pattern for formatting issue links from tags

22

- link_pattern (str): Pattern for formatting custom links from tags

23

- hide_excluded (bool): Whether to hide tests excluded by test plan

24

"""

25

26

def start_file(self):

27

"""

28

Start processing a new feature file.

29

Creates a new group context for organizing test results.

30

"""

31

32

def stop_feature(self):

33

"""

34

Complete processing of a feature file.

35

Exits the current group context and finalizes feature results.

36

"""

37

38

def start_scenario(self, scenario):

39

"""

40

Start processing a scenario, creating Allure test case.

41

42

Parameters:

43

- scenario: Behave scenario object with name, tags, and metadata

44

45

Creates:

46

- TestResult object with scenario metadata

47

- Scenario name, full name, and history ID

48

- Parameters from scenario outline tables

49

- Links and labels from scenario and feature tags

50

"""

51

52

def stop_scenario(self, scenario):

53

"""

54

Complete processing of a scenario.

55

56

Parameters:

57

- scenario: Behave scenario object with execution results

58

59

Handles:

60

- Test plan filtering and scenario exclusion

61

- Status determination from step results

62

- Final test result reporting or dropping

63

"""

64

65

def schedule_step(self, step):

66

"""

67

Schedule a step for execution tracking.

68

69

Parameters:

70

- step: Behave step object to be tracked

71

"""

72

73

def match_step(self, match):

74

"""

75

Process step match with step definition and start step execution.

76

77

Parameters:

78

- match: Behave match object linking step to implementation

79

"""

80

81

def start_behave_step(self, step):

82

"""

83

Start processing a Behave step, creating Allure step.

84

85

Parameters:

86

- step: Behave step object with keyword, name, text, and table

87

88

Creates:

89

- TestStepResult with step name and timing

90

- Text attachments for step text content

91

- CSV attachments for step tables

92

"""

93

94

def stop_behave_step(self, result):

95

"""

96

Complete processing of a Behave step.

97

98

Parameters:

99

- result: Behave result object with status, duration, and exceptions

100

101

Handles:

102

- Status determination from result

103

- Exception details and stack traces

104

- Step timing and final reporting

105

"""

106

107

def flush_steps(self):

108

"""

109

Process any remaining unmatched steps.

110

Used for scenarios that end without all steps being matched.

111

"""

112

113

def stop_session(self):

114

"""

115

End the test session and finalize all reporting.

116

Exits the root group context.

117

"""

118

```

119

120

### Allure Commons Hook Implementations

121

122

The AllureListener also implements hooks from the allure_commons system for advanced Allure features:

123

124

```python { .api }

125

def start_fixture(self, parent_uuid, uuid, name, parameters):

126

"""

127

Start an Allure fixture (before/after hooks).

128

129

Parameters:

130

- parent_uuid (str): UUID of parent test or group

131

- uuid (str): Unique identifier for this fixture

132

- name (str): Fixture name (e.g., "before_scenario", "after_feature")

133

- parameters (dict): Fixture parameters

134

"""

135

136

def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):

137

"""

138

Complete an Allure fixture.

139

140

Parameters:

141

- parent_uuid (str): UUID of parent test or group

142

- uuid (str): Fixture identifier

143

- name (str): Fixture name

144

- exc_type, exc_val, exc_tb: Exception information if fixture failed

145

"""

146

147

def start_test(self, parent_uuid, uuid, name, parameters, context):

148

"""

149

Start an Allure test (wraps start_scenario).

150

151

Parameters:

152

- parent_uuid (str): Parent group UUID

153

- uuid (str): Test UUID

154

- name (str): Test name

155

- parameters (dict): Test parameters

156

- context (dict): Test context containing scenario object

157

"""

158

159

def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb):

160

"""

161

Complete an Allure test (wraps stop_scenario).

162

163

Parameters:

164

- parent_uuid (str): Parent group UUID

165

- uuid (str): Test UUID

166

- name (str): Test name

167

- context (dict): Test context containing scenario object

168

- exc_type, exc_val, exc_tb: Exception information if test failed

169

"""

170

171

def start_step(self, uuid, title, params):

172

"""

173

Start an Allure step with parameters.

174

175

Parameters:

176

- uuid (str): Step UUID

177

- title (str): Step title/name

178

- params (dict): Step parameters

179

"""

180

181

def stop_step(self, uuid, exc_type, exc_val, exc_tb):

182

"""

183

Complete an Allure step.

184

185

Parameters:

186

- uuid (str): Step UUID

187

- exc_type, exc_val, exc_tb: Exception information if step failed

188

"""

189

190

def attach_data(self, body, name, attachment_type, extension):

191

"""

192

Attach data to current test or step.

193

194

Parameters:

195

- body: Data to attach (bytes or string)

196

- name (str): Attachment name

197

- attachment_type: Allure attachment type

198

- extension (str): File extension for attachment

199

"""

200

201

def attach_file(self, source, name, attachment_type, extension):

202

"""

203

Attach file to current test or step.

204

205

Parameters:

206

- source (str): Path to file to attach

207

- name (str): Attachment name

208

- attachment_type: Allure attachment type

209

- extension (str): File extension for attachment

210

"""

211

212

def add_description(self, test_description):

213

"""

214

Add description to current test.

215

216

Parameters:

217

- test_description (str): Plain text description

218

"""

219

220

def add_description_html(self, test_description_html):

221

"""

222

Add HTML description to current test.

223

224

Parameters:

225

- test_description_html (str): HTML formatted description

226

"""

227

228

def add_link(self, url, link_type, name):

229

"""

230

Add link to current test.

231

232

Parameters:

233

- url (str): Link URL

234

- link_type: Allure link type (ISSUE, LINK, etc.)

235

- name (str): Link display name

236

"""

237

```

238

239

### GroupContext Class

240

241

Internal helper class for managing test result container hierarchies:

242

243

```python { .api }

244

class GroupContext:

245

def __init__(self, logger):

246

"""

247

Initialize group context manager.

248

249

Parameters:

250

- logger: AllureReporter instance for result logging

251

"""

252

253

def enter(self):

254

"""

255

Enter a new group context level.

256

Creates a new TestResultContainer for organizing results.

257

"""

258

259

def exit(self):

260

"""

261

Exit the current group context level.

262

Finalizes the current container and removes it from the stack.

263

"""

264

265

def current_group(self):

266

"""

267

Get the current group container.

268

269

Returns:

270

TestResultContainer: Current group for organizing results

271

"""

272

273

def append_test(self, uuid):

274

"""

275

Add a test to all current group containers.

276

277

Parameters:

278

- uuid (str): Test UUID to add to containers

279

"""

280

```

281

282

## Configuration

283

284

The AllureListener reads configuration from behave's userdata:

285

286

```python

287

# Configuration is passed via behave command line or behave.ini

288

# -D AllureFormatter.issue_pattern=https://jira.company.com/browse/{}

289

# -D AllureFormatter.link_pattern=https://docs.company.com/{}

290

# -D AllureFormatter.hide_excluded=true

291

```

292

293

## Test Metadata Extraction

294

295

The listener automatically extracts metadata from Behave elements:

296

297

- **Scenario Names**: Uses scenario name or keyword as fallback

298

- **Parameters**: From scenario outline table rows

299

- **Links**: From `@issue.ABC-123` and `@link.DOC-456` style tags

300

- **Labels**: From `@severity.high`, `@tag.smoke` style tags

301

- **History ID**: MD5 hash of feature name, scenario name, and parameters

302

- **Full Names**: Combined feature and scenario names for identification

303

304

## Error Handling

305

306

The listener handles various error scenarios:

307

308

- **Undefined Steps**: Creates status details with implementation snippets

309

- **Failed Steps**: Captures exception messages and stack traces

310

- **Skipped Scenarios**: Handles test plan filtering and tag-based skipping

311

- **Parallel Execution**: Uses thread-local storage for state management