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

Method get_open_files

src/_pytest/pytester.py:123–158  ·  src/_pytest/pytester.py::LsofFdLeakChecker.get_open_files
(self)

Source from the content-addressed store, hash-verified

121
122class LsofFdLeakChecker:
123 def get_open_files(self) -> list[tuple[str, str]]:
124 if sys.version_info >= (3, 11):
125 class="cm"># New in Python 3.11, ignores utf-8 mode
126 encoding = locale.getencoding()
127 else:
128 encoding = locale.getpreferredencoding(False)
129 out = subprocess.run(
130 (class="st">"lsof", class="st">"-Ffn0", class="st">"-p", str(os.getpid())),
131 stdout=subprocess.PIPE,
132 stderr=subprocess.DEVNULL,
133 check=True,
134 text=True,
135 encoding=encoding,
136 ).stdout
137
138 def isopen(line: str) -> bool:
139 return line.startswith(class="st">"f") and (
140 class="st">"deleted" not in line
141 and class="st">"mem" not in line
142 and class="st">"txt" not in line
143 and class="st">"cwd" not in line
144 )
145
146 open_files = []
147
148 for line in out.split(class="st">"\n"):
149 if isopen(line):
150 fields = line.split(class="st">"\0")
151 fd = fields[0][1:]
152 filename = fields[1][1:]
153 if filename in IGNORE_PAM:
154 continue
155 if filename.startswith(class="st">"/"):
156 open_files.append((fd, filename))
157
158 return open_files
159
160 def matching_platform(self) -> bool:
161 try:

Callers 1

Calls 2

appendMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected