(self, item: Item)
| 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 |
no test coverage detected