Skip to content

[FEATURE] Allow adding attachments to trace #310

Closed

Description

Allow users to add attachments to the playwright trace viewer, similar to how it's done in Node.js

Activity

  1. anupamkr1708 commented on Aug 25, 2026

    @anupamkr1708

    Hi Tanner Larson (@TannerLarson), I looked through the existing pytest-playwright tracing flow and the corresponding Playwright trace-viewer support. I'd like to take this as a focused contribution and look at how attachments can be exposed through the pytest integration while keeping the existing tracing behavior unchanged.

    I’ll first verify the current fixture/lifecycle and the underlying trace attachment support, then I can propose the smallest implementation and test scope. Please let me know if you'd prefer any particular API shape.

  2. anupamkr1708 commented on Aug 26, 2026

    @anupamkr1708

    Hi Tanner Larson (@TannerLarson), I dug into the tracing path and found an important limitation before starting implementation.

    testInfo.attach() in Node is implemented by the @playwright/test runner itself: it maintains a separate test-trace stream and merges that with the browser trace when the test finishes. The shared Playwright tracing API used by Python doesn't currently expose an equivalent attachment operation.

    I also checked playwright-pytest's ArtifactsRecorder: it only starts/stops the browser trace and manages the resulting trace.zip; it has no supported way to inject attachment entries into the trace.

    So I don't think this can be implemented cleanly in playwright-pytest alone without depending on Playwright internals. It looks like some upstream support would be needed first. Would you prefer that I track this as an upstream Playwright/Python capability and then revisit the pytest integration once that exists?

  3. TannerLarson commented on Aug 31, 2026

    @TannerLarson
    Author

    Yeah, that would be fine. Full transparency, I've since mostly moved to Node.js directly, so I'm not as keen on this feature any more

  4. pavelfeldman commented on Oct 8, 2026

    @pavelfeldman
    Member

    Thanks for the investigation, ANUPAM KUMAR (@anupamkr1708). In Node, attachments come from the test runner's own trace stream, which isn't exposed through the Python tracing API (playwright 1.63's Tracing has start/stop/chunks/groups/HAR, no attach), so this can't be done cleanly in pytest-playwright today. Since the original need has gone away, I'm closing this. If more people need it we can revisit it together with a Python-side API; the report attachments from #121 (report.user_properties, pytest-html) cover the non-trace-viewer part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions