Skip to content

Commit 901b773

Browse files
committed
Validate xunit2 files against the schema
Fix pytest-dev#5095
1 parent f5fab2b commit 901b773

File tree

4 files changed

+340
-119
lines changed

4 files changed

+340
-119
lines changed

changelog/5095.trivial.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
XML files of the ``xunit2`` family are now validated against the schema by pytest's own test suite
2+
to avoid future regressions.

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ def main():
2121
use_scm_version={"write_to": "src/_pytest/_version.py"},
2222
setup_requires=["setuptools-scm", "setuptools>=40.0"],
2323
package_dir={"": "src"},
24-
# fmt: off
2524
extras_require={
2625
"testing": [
2726
"argcomplete",
2827
"hypothesis>=3.56",
2928
"mock",
3029
"nose",
3130
"requests",
32-
],
31+
"xmlschema",
32+
]
3333
},
34-
# fmt: on
3534
install_requires=INSTALL_REQUIRES,
3635
)
3736

testing/example_scripts/junit-10.xsd

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2014, Gregory Boissinot
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
-->
25+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
26+
<xs:simpleType name="SUREFIRE_TIME">
27+
<xs:restriction base="xs:string">
28+
<xs:pattern value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
29+
</xs:restriction>
30+
</xs:simpleType>
31+
32+
<xs:complexType name="rerunType" mixed="true"> <!-- mixed (XML contains text) to be compatible with version previous than 2.22.1 -->
33+
<xs:sequence>
34+
<xs:element name="stackTrace" type="xs:string" minOccurs="0" /> <!-- optional to be compatible with version previous than 2.22.1 -->
35+
<xs:element name="system-out" type="xs:string" minOccurs="0" />
36+
<xs:element name="system-err" type="xs:string" minOccurs="0" />
37+
</xs:sequence>
38+
<xs:attribute name="message" type="xs:string" />
39+
<xs:attribute name="type" type="xs:string" use="required" />
40+
</xs:complexType>
41+
42+
<xs:element name="failure">
43+
<xs:complexType mixed="true">
44+
<xs:attribute name="type" type="xs:string"/>
45+
<xs:attribute name="message" type="xs:string"/>
46+
</xs:complexType>
47+
</xs:element>
48+
49+
<xs:element name="error">
50+
<xs:complexType mixed="true">
51+
<xs:attribute name="type" type="xs:string"/>
52+
<xs:attribute name="message" type="xs:string"/>
53+
</xs:complexType>
54+
</xs:element>
55+
56+
<xs:element name="skipped">
57+
<xs:complexType mixed="true">
58+
<xs:attribute name="type" type="xs:string"/>
59+
<xs:attribute name="message" type="xs:string"/>
60+
</xs:complexType>
61+
</xs:element>
62+
63+
<xs:element name="properties">
64+
<xs:complexType>
65+
<xs:sequence>
66+
<xs:element ref="property" minOccurs="0" maxOccurs="unbounded"/>
67+
</xs:sequence>
68+
</xs:complexType>
69+
</xs:element>
70+
71+
<xs:element name="property">
72+
<xs:complexType>
73+
<xs:attribute name="name" type="xs:string" use="required"/>
74+
<xs:attribute name="value" type="xs:string" use="required"/>
75+
</xs:complexType>
76+
</xs:element>
77+
78+
<xs:element name="system-err" type="xs:string"/>
79+
<xs:element name="system-out" type="xs:string"/>
80+
<xs:element name="rerunFailure" type="rerunType"/>
81+
<xs:element name="rerunError" type="rerunType"/>
82+
<xs:element name="flakyFailure" type="rerunType"/>
83+
<xs:element name="flakyError" type="rerunType"/>
84+
85+
<xs:element name="testcase">
86+
<xs:complexType>
87+
<xs:sequence>
88+
<xs:choice minOccurs="0" maxOccurs="unbounded">
89+
<xs:element ref="skipped"/>
90+
<xs:element ref="error"/>
91+
<xs:element ref="failure"/>
92+
<xs:element ref="rerunFailure" minOccurs="0" maxOccurs="unbounded"/>
93+
<xs:element ref="rerunError" minOccurs="0" maxOccurs="unbounded"/>
94+
<xs:element ref="flakyFailure" minOccurs="0" maxOccurs="unbounded"/>
95+
<xs:element ref="flakyError" minOccurs="0" maxOccurs="unbounded"/>
96+
<xs:element ref="system-out"/>
97+
<xs:element ref="system-err"/>
98+
</xs:choice>
99+
</xs:sequence>
100+
<xs:attribute name="name" type="xs:string" use="required"/>
101+
<xs:attribute name="time" type="xs:string"/>
102+
<xs:attribute name="classname" type="xs:string"/>
103+
<xs:attribute name="group" type="xs:string"/>
104+
</xs:complexType>
105+
</xs:element>
106+
107+
<xs:element name="testsuite">
108+
<xs:complexType>
109+
<xs:choice minOccurs="0" maxOccurs="unbounded">
110+
<xs:element ref="testsuite"/>
111+
<xs:element ref="properties"/>
112+
<xs:element ref="testcase"/>
113+
<xs:element ref="system-out"/>
114+
<xs:element ref="system-err"/>
115+
</xs:choice>
116+
<xs:attribute name="name" type="xs:string" use="required"/>
117+
<xs:attribute name="tests" type="xs:string" use="required"/>
118+
<xs:attribute name="failures" type="xs:string" use="required"/>
119+
<xs:attribute name="errors" type="xs:string" use="required"/>
120+
<xs:attribute name="group" type="xs:string" />
121+
<xs:attribute name="time" type="SUREFIRE_TIME"/>
122+
<xs:attribute name="skipped" type="xs:string" />
123+
<xs:attribute name="timestamp" type="xs:string" />
124+
<xs:attribute name="hostname" type="xs:string" />
125+
<xs:attribute name="id" type="xs:string" />
126+
<xs:attribute name="package" type="xs:string" />
127+
<xs:attribute name="file" type="xs:string"/>
128+
<xs:attribute name="log" type="xs:string"/>
129+
<xs:attribute name="url" type="xs:string"/>
130+
<xs:attribute name="version" type="xs:string"/>
131+
</xs:complexType>
132+
</xs:element>
133+
134+
<xs:element name="testsuites">
135+
<xs:complexType>
136+
<xs:sequence>
137+
<xs:element ref="testsuite" minOccurs="0" maxOccurs="unbounded" />
138+
</xs:sequence>
139+
<xs:attribute name="name" type="xs:string" />
140+
<xs:attribute name="time" type="SUREFIRE_TIME"/>
141+
<xs:attribute name="tests" type="xs:string" />
142+
<xs:attribute name="failures" type="xs:string" />
143+
<xs:attribute name="errors" type="xs:string" />
144+
</xs:complexType>
145+
</xs:element>
146+
147+
</xs:schema>

0 commit comments

Comments
 (0)