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

Method pytest_runtest_protocol

src/_pytest/pytester.py:165–186  ·  view source on GitHub ↗
(self, item: Item)

Source from the content-addressed store, hash-verified

163
164 @hookimpl(hookwrapper=True, tryfirst=True)
165 def pytest_runtest_protocol(self, item: Item) -> Generator[None, None, None]:
166 lines1 = self.get_open_files()
167 yield
168 if hasattr(sys, "pypy_version_info"):
169 gc.collect()
170 lines2 = self.get_open_files()
171
172 new_fds = {t[0] for t in lines2} - {t[0] for t in lines1}
173 leaked_files = [t for t in lines2 if t[0] in new_fds]
174 if leaked_files:
175 error = [
176 "***** %s FD leakage detected" % len(leaked_files),
177 *(str(f) for f in leaked_files),
178 "*** Before:",
179 *(str(f) for f in lines1),
180 "*** After:",
181 *(str(f) for f in lines2),
182 "***** %s FD leakage detected" % len(leaked_files),
183 "*** function %s:%s: %s " % item.location,
184 "See issue #2366",
185 ]
186 item.warn(PytestWarning("\n".join(error)))
187
188
189# used at least by pytest-xdist plugin

Callers 1

pytest_runtestloopFunction · 0.80

Calls 4

get_open_filesMethod · 0.95
PytestWarningClass · 0.90
collectMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected