60 Resolve the given path to an absolute path,
61 expanding environment variables.
62 If path looks relative and does not point to anything
65 if isinstance(path, Path):
67 path = os.path.expandvars(path)
72 path, suffix = path.rsplit(
":", 1)
75 if not os.path.isabs(path):
76 base_dir = file_path_for_class(cls).parent
77 possible_path = str((base_dir / path).resolve())
78 if os.path.exists(possible_path):
163 Run the specified program and capture its output.
165 start_time = datetime.now()
168 proc = subprocess.Popen(
170 stdout=subprocess.PIPE,
171 stderr=subprocess.PIPE,
176 stdout_chunks, stderr_chunks = [], []
178 exceeded_stream = stack_trace = run_exception =
None
180 proc.stdout.fileno(): (stdout_chunks,
"stdout"),
181 proc.stderr.fileno(): (stderr_chunks,
"stderr"),
185 nonlocal stdout, stderr, exceeded_stream
186 while not exceeded_stream
and proc.poll()
is None:
187 readable, _, _ = select.select(streams.keys(), [], [], cls.
timeout)
188 for fileno
in readable:
189 data = os.read(fileno, 1024)
190 chunks, stream_name = streams[fileno]
192 if sum(len(chunk)
for chunk
in chunks) > STDOUT_LIMIT:
193 exceeded_stream = stream_name
196 stdout = b
"".join(stdout_chunks)
197 stderr = b
"".join(stderr_chunks)
199 thread = threading.Thread(target=read_output)
203 if thread.is_alive():
206 elif exceeded_stream:
208 "Stream exceeded size limit", exceeded_stream
211 end_time = datetime.now()
213 completed_process = subprocess.CompletedProcess(
215 returncode=proc.returncode,
226 env_to_record.extend(
227 env[name]
for name
in env
if re.match(
r"GAUDI_ENV_TO_RECORD(_\d+)?", name)
231 for key, value
in env.items()
232 if any(re.match(exp, key)
for exp
in env_to_record)
235 completed_process=completed_process,
236 start_time=start_time,
238 run_exception=run_exception,
240 expanded_command=command,
260 record_property: Callable[[str, str],
None],
261 fixture_result: FixtureResult,
262 reference_path: Optional[Path],
265 Record properties and handle any failures during fixture setup.
267 for key, value
in fixture_result.to_dict().items():
268 if value
is not None:
269 record_property(key, value)
271 record_property(
"reference_file", str(reference_path))
273 if fixture_result.run_exception:
274 pytest.fail(f
"{fixture_result.run_exception}")