Skip to content

Commit e43f064

Browse files
authored
Add ability to Skip a step (#16)
1 parent f29bdf4 commit e43f064

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

example/example_parameters_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package example
22

33
import (
44
"fmt"
5+
"testing"
6+
57
"github.com/dailymotion/allure-go"
68
"github.com/dailymotion/allure-go/severity"
7-
"testing"
89
)
910

1011
type SampleObject struct {
@@ -56,7 +57,7 @@ func TestAllureStepWithParameters(t *testing.T) {
5657
for i := 0; i < 5; i++ {
5758
allure.StepWithParameter("Step with parameters", map[string]interface{}{"counter": i}, func() {})
5859
}
59-
60+
allure.SkipStepWithParameter("Step with parameters", "Skip this step with parameters", map[string]interface{}{"counter": 6}, func() {})
6061
})
6162
}
6263

example/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestWithIntricateSubsteps(t *testing.T) {
2323
t.Errorf("Failure")
2424
})
2525
allure.Step("Sub-step 1.2", func() {})
26+
allure.SkipStep("Sub-step 1.3", "Skip this step because of defect to be fixed", func() {})
2627
})
2728
allure.Step("Step 2", func() {
2829
allure.Step("Sub-step 2.1", func() {

step.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
)
99

1010
type stepObject struct {
11-
Name string `json:"name,omitempty"`
12-
Status string `json:"status,omitempty"`
13-
Stage string `json:"stage"`
14-
ChildrenSteps []stepObject `json:"steps"`
15-
Attachments []attachment `json:"attachments"`
16-
Parameters []Parameter `json:"parameters"`
17-
Start int64 `json:"start"`
18-
Stop int64 `json:"stop"`
11+
Name string `json:"name,omitempty"`
12+
Status string `json:"status,omitempty"`
13+
StatusDetail statusDetails `json:"statusDetails,omitempty"`
14+
Stage string `json:"stage"`
15+
ChildrenSteps []stepObject `json:"steps"`
16+
Attachments []attachment `json:"attachments"`
17+
Parameters []Parameter `json:"parameters"`
18+
Start int64 `json:"start"`
19+
Stop int64 `json:"stop"`
1920
}
2021

2122
func (s *stepObject) GetSteps() []stepObject {
@@ -39,6 +40,12 @@ func Step(description string, action func()) {
3940
StepWithParameter(description, nil, action)
4041
}
4142

43+
// SkipStep doesn't execute the action and marks the step as skipped in report
44+
// Reason won't appear in report until https://github.com/allure-framework/allure2/issues/774 is fixed
45+
func SkipStep(description, reason string, action func()) {
46+
SkipStepWithParameter(description, reason, nil, action)
47+
}
48+
4249
// StepWithParameter is meant to be wrapped around actions with the purpose of logging the parameters
4350
func StepWithParameter(description string, parameters map[string]interface{}, action func()) {
4451
step := newStep()
@@ -69,6 +76,26 @@ func StepWithParameter(description string, parameters map[string]interface{}, ac
6976
step.Status = "passed"
7077
}
7178

79+
// SkipStepWithParameter doesn't execute the action and marks the step as skipped in report
80+
// Reason won't appear in report until https://github.com/allure-framework/allure2/issues/774 is fixed
81+
func SkipStepWithParameter(description, reason string, parameters map[string]interface{}, action func()) {
82+
step := newStep()
83+
step.Start = getTimestampMs()
84+
step.Name = description
85+
if parameters == nil || len(parameters) > 0 {
86+
step.Parameters = convertMapToParameters(parameters)
87+
}
88+
step.Status = "skipped"
89+
step.StatusDetail.Message = reason
90+
if currentStepObj, ok := ctxMgr.GetValue(nodeKey); ok {
91+
currentStep := currentStepObj.(hasSteps)
92+
currentStep.AddStep(*step)
93+
} else {
94+
log.Fatalln("could not retrieve current allure node")
95+
}
96+
step.Stop = getTimestampMs()
97+
}
98+
7299
func newStep() *stepObject {
73100
return &stepObject{
74101
Attachments: make([]attachment, 0),

0 commit comments

Comments
 (0)