MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _NodeReporter

Class _NodeReporter

src/_pytest/junitxml.py:89–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88
89class _NodeReporter:
90 def __init__(self, nodeid: Union[str, TestReport], xml: "LogXML") -> None:
91 self.id = nodeid
92 self.xml = xml
93 self.add_stats = self.xml.add_stats
94 self.family = self.xml.family
95 self.duration = 0
96 self.properties: List[Tuple[str, str]] = []
97 self.nodes: List[ET.Element] = []
98 self.attrs: Dict[str, str] = {}
99
100 def append(self, node: ET.Element) -> None:
101 self.xml.add_stats(node.tag)
102 self.nodes.append(node)
103
104 def add_property(self, name: str, value: object) -> None:
105 self.properties.append((str(name), bin_xml_escape(value)))
106
107 def add_attribute(self, name: str, value: object) -> None:
108 self.attrs[str(name)] = bin_xml_escape(value)
109
110 def make_properties_node(self) -> Optional[ET.Element]:
111 """Return a Junit node containing custom properties, if any."""
112 if self.properties:
113 properties = ET.Element("properties")
114 for name, value in self.properties:
115 properties.append(ET.Element("property", name=name, value=value))
116 return properties
117 return None
118
119 def record_testreport(self, testreport: TestReport) -> None:
120 names = mangle_test_address(testreport.nodeid)
121 existing_attrs = self.attrs
122 classnames = names[:-1]
123 if self.xml.prefix:
124 classnames.insert(0, self.xml.prefix)
125 attrs: Dict[str, str] = {
126 "classname": ".".join(classnames),
127 "name": bin_xml_escape(names[-1]),
128 "file": testreport.location[0],
129 }
130 if testreport.location[1] is not None:
131 attrs["line"] = str(testreport.location[1])
132 if hasattr(testreport, "url"):
133 attrs["url"] = testreport.url
134 self.attrs = attrs
135 self.attrs.update(existing_attrs) # Restore any user-defined attributes.
136
137 # Preserve legacy testcase behavior.
138 if self.family == "xunit1":
139 return
140
141 # Filter out attributes not permitted by this test family.
142 # Including custom attributes because they are not valid here.
143 temp_attrs = {}
144 for key in self.attrs.keys():
145 if key in families[self.family]["testcase"]:
146 temp_attrs[key] = self.attrs[key]

Callers 1

node_reporterMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected