(self, item: Item)
| 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, "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 | f"***** {len(leaked_files)} FD leakage detected", |
| 183 | *(str(f) for f in leaked_files), |
| 184 | "*** Before:", |
| 185 | *(str(f) for f in lines1), |
| 186 | "*** After:", |
| 187 | *(str(f) for f in lines2), |
| 188 | f"***** {len(leaked_files)} FD leakage detected", |
| 189 | "*** function {}:{}: {} ".format(*item.location), |
| 190 | "See issue #2366", |
| 191 | ] |
| 192 | item.warn(PytestFDWarning("\n".join(error))) |
| 193 | |
| 194 | |
| 195 | # used at least by pytest-xdist plugin |
no test coverage detected