Skip to content

Add server-side errors to pytest report - #521

Open
csernazs wants to merge 2 commits into
masterfrom
makereport
Open

csernazs wants to merge 2 commits into
masterfrom
makereport

Conversation

@csernazs

Copy link
Copy Markdown
Owner

No description provided.

Comment thread pytest_httpserver/pytest_plugin.py Outdated
servers = []
node.stash[SERVERS_STASH_KEY] = servers
if server not in servers:
servers.append(server)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will leak :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, The stash entry is never removed, and pytest keeps items in session.items, so for a function-scoped custom server (the BlockingHTTPServer example) the stopped server, its log and handlers stay referenced until the session ends — harmless for the plugin's own session-scoped servers.

Comment thread pytest_httpserver/pytest_plugin.py Outdated
"Note: these errors were not raised because the test did not call the check "
"methods of the server (for example HTTPServer.check())."
)
report.sections.append((REPORT_SECTION_TITLE, "\n".join(section_lines)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found while testing: when a test fails in both call and teardown, this section gets appended twice — once to each failed report. It doesn't happen on the last test of a session, because the session-scoped server is cleared before that teardown report is built, which makes it easy to miss.

Deleting the stash right after this append (and at the teardown report when there's nothing to report) fixes it and releases the references

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @EduardoLZevallos

So I asked my agent again to fix this (right now I still consider it as a proof of concept), it claims it is fixed and there's a test added for this.

I'm still unsure if this is the right implementation, perhaps I'll take a closer look later. I need to be more familiar with pytest semantics and hooks, this current implementation seems overcomplicated for my first sight. :)

Thanks for keeping feedback on this.

Once this code is cleaned up (and most importantly: understood by me) I think this thing will be first put behind a feature flag (eg. envvar or such), and it will be opt-in.

Zsolt

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants