MCPcopy
hub / github.com/pytest-dev/pytest / pytest_runtest_protocol

Method pytest_runtest_protocol

src/_pytest/pytester.py:169–192  ·  src/_pytest/pytester.py::LsofFdLeakChecker.pytest_runtest_protocol
(self, item: Item)

Source from the content-addressed store, hash-verified

167
168 @hookimpl(wrapper=True, tryfirst=True)
169 def pytest_runtest_protocol(self, item: Item) -> Generator[None, object, object]:
170 lines1 = self.get_open_files()
171 try:
172 return (yield)
173 finally:
174 if hasattr(sys, class="st">"pypy_version_info"):
175 gc.collect()
176 lines2 = self.get_open_files()
177
178 new_fds = {t[0] for t in lines2} - {t[0] for t in lines1}
179 leaked_files = [t for t in lines2 if t[0] in new_fds]
180 if leaked_files:
181 error = [
182 fclass="st">"***** {len(leaked_files)} FD leakage detected",
183 *(str(f) for f in leaked_files),
184 class="st">"*** Before:",
185 *(str(f) for f in lines1),
186 class="st">"*** After:",
187 *(str(f) for f in lines2),
188 fclass="st">"***** {len(leaked_files)} FD leakage detected",
189 class="st">"*** function {}:{}: {} ".format(*item.location),
190 class="st">"See issue class="cm">#2366",
191 ]
192 item.warn(PytestFDWarning(class="st">"\n".join(error)))
193
194
195class="cm"># used at least by pytest-xdist plugin

Callers 1

pytest_runtestloopFunction · 0.80

Calls 6

get_open_filesMethod · 0.95
PytestFDWarningClass · 0.90
joinMethod · 0.80
collectMethod · 0.45
formatMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected