77Copyright: MIT, Timo Furrer <[email protected] > 88"""
99
10+ import re
1011from datetime import datetime , timezone
1112
1213import pytest
1617from radish .feature import Feature
1718from radish .model import Tag
1819from radish .scenario import Scenario
20+ from radish .stepmodel import Step
1921from radish .terrain import world
2022
2123
@@ -27,7 +29,7 @@ def test_empty_feature_list():
2729 writer .generate_junit_xml (no_features , "marker-is-ignored" )
2830
2931
30- def test_singel_feature_list (mocker ):
32+ def test_single_feature_list (mocker ):
3133 stub = mocker .patch ("radish.extensions.junit_xml_writer.JUnitXMLWriter._write_xml_to_disk" )
3234
3335 first_feature = Feature (1 , "Feature" , "I am a feature" , "foo.feature" , 1 , tags = None )
@@ -108,3 +110,33 @@ def test_relaxed_mode_adding_tags_to_junit(mocker):
108110
109111 assert "author" in str (stub .call_args [0 ])
110112 assert "batman" in str (stub .call_args [0 ])
113+
114+
115+ def test_early_exit_feature_list (mocker ):
116+ stub = mocker .patch ("radish.extensions.junit_xml_writer.JUnitXMLWriter._write_xml_to_disk" )
117+
118+ first_feature = Feature (1 , "Feature" , "I am a feature" , "foo.feature" , 1 , tags = None )
119+ first_feature .starttime = datetime .now (timezone .utc )
120+ first_feature .endtime = datetime .now (timezone .utc )
121+ second_feature = Feature (2 , "Feature" , "Did not run" , "foo.feature" , 1 , tags = None )
122+ scenario = Scenario (
123+ 1 , "Scenario" , "Did not run" , "foo.feature" , 1 , parent = None , tags = None , preconditions = None , background = None
124+ )
125+ scenario .steps = [Step (1 , "Foo" , "foo.feature" , 2 , None , False )]
126+ second_feature .scenarios = [scenario ]
127+ assert second_feature .state not in [Step .State .PASSED , Step .State .FAILED ]
128+
129+ features = [first_feature , second_feature ]
130+
131+ writer = JUnitXMLWriter ()
132+ writer .generate_junit_xml (features , "marker-is-ignored" )
133+
134+ result = str (stub .call_args [0 ])
135+ feature_regex = re .compile (r"<testsuite[^>]*name=\"([^\"]+)\"([^>]*)>" )
136+ matches = feature_regex .findall (result )
137+ assert len (matches ) == 2
138+ f1_match = next (m for m in matches if m [0 ] == "I am a feature" )
139+ f2_match = next (m for m in matches if m [0 ] == "Did not run" )
140+ assert 'tests="0"' in f1_match [1 ] # f1 contains no scenarios
141+ assert 'skipped="1"' in f2_match [1 ] # f2 contains one untested scenario (it was skipped)
142+ assert "<skipped" in result # there is a skipped testcase element
0 commit comments