MCPcopy Create free account
hub / github.com/microsoft/debugpy / test_wrapper

Function test_wrapper

tests/pytest_fixtures.py:39–115  ·  view source on GitHub ↗
(request, long_tmpdir)

Source from the content-addressed store, hash-verified

37
38@pytest.fixture(autouse=True)
39def test_wrapper(request, long_tmpdir):
40 def write_log(filename, data):
41 filename = os.path.join(log.log_dir, filename)
42 if not isinstance(data, bytes):
43 data = data.encode("utf-8")
44 with open(filename, "wb") as f:
45 f.write(data)
46
47 session.Session.reset_counter()
48
49 # Add worker-specific isolation for tmpdir and log directory
50 try:
51 worker_id = os.environ.get("PYTEST_XDIST_WORKER", "gw0")
52 worker_suffix = f"_{worker_id}"
53 except Exception:
54 worker_suffix = ""
55
56 session.Session.tmpdir = long_tmpdir / f"session{worker_suffix}"
57 session.Session.tmpdir.ensure(dir=True)
58 original_log_dir = log.log_dir
59
60 failed = True
61 try:
62 if log.log_dir is None:
63 log.log_dir = (long_tmpdir / f"debugpy_logs{worker_suffix}").strpath
64 else:
65 log_subdir = request.node.nodeid
66 log_subdir = log_subdir.replace("::", "/")
67 for ch in r":?*|<>":
68 log_subdir = log_subdir.replace(ch, f"&#{ord(ch)};")
69 log.log_dir += "/" + log_subdir + worker_suffix
70
71 try:
72 py.path.local(log.log_dir).remove()
73 except Exception:
74 pass
75
76 print("\n") # make sure on-screen logs start on a new line
77 with log.to_file(prefix="tests"):
78 timestamp.reset()
79 log.info("{0} started.", request.node.nodeid)
80 log.describe_environment("Environment:")
81 try:
82 yield
83 finally:
84 failed = False
85 for report_attr in ("setup_report", "call_report", "teardown_report"):
86 try:
87 report = getattr(request.node, report_attr)
88 except AttributeError:
89 continue
90
91 failed |= report.failed
92 log.write_format(
93 "error" if report.failed else "info",
94 "pytest {0} phase for {1} {2}.",
95 report.when,
96 request.node.nodeid,

Callers

nothing calls this directly

Calls 7

write_logFunction · 0.85
reset_counterMethod · 0.80
resetMethod · 0.80
infoMethod · 0.80
dumpMethod · 0.80
getMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…