Optional HTTP request/response attachment in Allure Reports#3
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a streamlined way for test authors to capture and attach full HTTP request/response details into Allure reports by simply passing a boolean flag (
attach=True) on any client call. With this change, there's no need for manialallure.attach(...)calls in test code. Authors can focus on endpoint calls and assertions, and the framework handles the rest.What's Changed
1. Per-Call "attach" Flag
get,post,put,delete) in the coreAPIClientnow accept a keyword-only parameterattach: bool = False.attach=True, the framework will automatically record both the outgoingRequestand incomingResponseand push them as attachments into the Allure report.2. Request/Response Recording & Attachment helpers
Introduced private fields to hold the most recent
RequestandResponseobjects.Added a
_record_request(request)helper that saves the builthttpx.Requestjust before sending.Added a
_attach_last_exchange_to_allure()helper that usesallure.attach(...)to add these details to the report, including:3. Preserving Normal Behavior
attach=Trueremain unchanged. No attachments are produced, and the core API logic behaves identically to before.APIErroris still raised; but ifattach=True, the request/response will still be attached to Allure before the error propagates.4. Updated Spotify-Specific Client
get_new_releases,get_artist_top_tracks) now accept theattachflag and pass it through to the underlyinggetcall. This lets integration tests capture those HTTP exchanges without additional code.5. Test Coverage
Existing unit tests were extended to cover the
attach=Truepath:client.get(..., attach=True)still returns the expected JSON body without errors.attach=Truestill raisesAPIErrorbut does not crash during attachment.attach=Truecontinue to work as expected.How to Verify Locally
1. Install dependencies
(This runs
poetry install, ensuringallure-pytestandhttpxare available.)2. Run Unit Tests
make testattach=False(default) andattach=Truecases.3. Generate and Serve Allure Report
Choose or write a test that calls, for example,
client.get("/some-endpoint", attach=True).In the Allure UI, open that test's details. Under Attachments, you should see:
4. Test Error Case
client.get("/error", attach=True)in a test. The test should raiseAPIError, and the Allure rpeort should show the recorded request and failing response under that test's attachments.By adding the
attachflag, test authors can now capture HTTP exhanges with a single boolean argument. No more manualallure.attach(...)calls scattered throughout test code. This simplifies debugging and accelerates development when diagnosing API issues. Let me know if you have any questions!