httpserver fixtures clear assertions before checking them, so check_assertions() can never fail a test

Open
#3,506 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@liquidsec is already working on this.

Since Oct 7, 2026.

  • #3614 by @FemaleDev — open

Assessment

This issue has not been assessed yet.

Description

bug tests

Summary

Every check_assertions() call in the suite is preceded by clear(), which empties the list check_assertions() reads. The call can never raise, so pytest_httpserver has never been able to fail a bbot test.

Mechanism

bbot/test/conftest.py:125-131:

yield server

server.clear()              # wipes server.assertions
stop_server(server)

server.check_assertions()   # list is empty, nothing to raise
server.clear()

HTTPServerBase.clear() is:

def clear(self):
    self.clear_assertions()      # self.assertions = []
    self.clear_handler_errors()
    self.clear_log()
    self.no_handler_status_code = 500

Four call sites, all the same pattern: conftest.py:130, conftest.py:149, conftest.py:256, and test_step_1/test_manager_scope_accuracy.py:47.

What is not being caught

Three things append to assertions in the server class we use:

Site Condition Live today?
httpserver.py:853 (respond_nohandler) a request matched no registered handler yes, constantly
httpserver.py:1252 (respond_permanent_failure) an ordered matcher was missed no, nothing in the suite calls expect_ordered_request
httpserver.py:1304 (dispatch) a handler function raised AssertionError yes

The third has no other path back to the test process. It is recorded and re-raised, but the re-raise happens on the werkzeug thread, so the test sees only the resulting error response.

check_handler_errors() is never called anywhere in the suite either, so a handler raising a non-AssertionError exception lands in handler_errors and is also never read.

The practical consequence is on the first site. If a module test registers set_expect_requests(uri="/foo") and the module requests /foo/, or the request never fires at all, the server returns no_handler_status_code and the test lives or dies on its own event assertions. For a test that asserts a finding is not produced, that passes for the wrong reason: the module never received the response that would have triggered it.

Why the obvious fix does not work

Moving clear() to after check_assertions() would make the no-handler assertion fire on every test that makes an unmatched request. In a brute-force-heavy suite that is thousands of them by design; webbrute_shortnames alone issues 4318 misses deliberately. Those misses are the expected case, not a defect.

So the no-handler producer should stay suppressed, which #3404 already does by overriding respond_nohandler to return a body without calling add_assertion. What is worth recovering is the handler-AssertionError path and check_handler_errors, which fire only on genuine test-authoring mistakes.

Suggested shape

  • Drop the clear() from before check_assertions(), keep the one after.
  • Call check_handler_errors() alongside it.
  • Keep the respond_nohandler override so deliberate misses stay silent.

Found while reviewing #3404, which identified the dead assertion and correctly scoped its own change to the miss body.

Dominant language
Python
Stars
10.9k
Forks
959
Avg merge
2d 7h
Merged PRs (30d)
84

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from blacklanternsecurity/bbot

All issues in blacklanternsecurity/bbot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.