getContext function

TestContext? getContext()

Returns the pin for the current async context, falling back to the host resolver and the isolate-wide pin, or null outside a reported test.

Capture this before handing work to an unrelated future or isolate and re-pin it with runWithContext; a zone that was never pinned reports nothing.

Implementation

TestContext? getContext() {
  final zoneValue = Zone.current[_zoneKey];
  if (zoneValue is TestContext) return zoneValue;
  // package:test `--concurrency` overlaps tests in one isolate — the runner
  // resolves the LiveTest-scoped pin here so comments/steps do not cross wires.
  final fromHost = resolveHostContext?.call();
  if (fromHost != null) return fromHost;
  return _isolateContext;
}