# Make `capture_log` assertions test-specific

Do not assert on generic text in logs captured by async tests.

```elixir
log = capture_log(fn -> Billing.sync(invoice.id) end)

assert log =~ "failed"
refute log =~ "unexpected response"
```

`ExUnit.CaptureLog` warns that a test using `async: true` can capture messages from other tests. That makes both assertions timing-dependent: the positive assertion can pass because an unrelated test logged `"failed"`, while the negative assertion can fail because another process logged `"unexpected response"`.

Put a stable, operation-specific marker in the message and match that identifying fragment:

```elixir
Logger.error(
  "billing_sync invoice=#{invoice.id} failed: #{inspect(reason)}"
)

assert log =~ "billing_sync invoice=#{invoice.id} failed:"
```

The partial match still ignores timestamps and formatter details, but it no longer matches every failure in the concurrent suite. Use a resource identifier that is unique to the test when concurrent tests can exercise the same operation.

If correctness requires proving that no matching log occurred anywhere, or the message cannot be made test-specific, move that test module out of the async pool instead of treating `capture_log/2` as process isolation.

[Read the `ExUnit.CaptureLog` documentation](https://hexdocs.pm/ex_unit/ExUnit.CaptureLog.html)


---

Created by: almirsarajcic
Date: September 09, 2026
URL: https://elixirdrops.net/d/3HNPGZjp
