httpserver fixtures clear assertions before checking them, so check_assertions() can never fail a test
Maintainers usually reply within 2 days
Assessment
This issue has not been assessed yet.
Description
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 beforecheck_assertions(), keep the one after. - Call
check_handler_errors()alongside it. - Keep the
respond_nohandleroverride 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from blacklanternsecurity/bbot
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
blacklanternsecurity/bbot#3679 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
blacklanternsecurity/bbot#3678 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
blacklanternsecurity/bbot#3671 ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 22/100
blacklanternsecurity/bbot#3646 · 2 reactions ·
Maintainers usually reply within 2 days
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 58/100
blacklanternsecurity/bbot#3630 · 1 assignee ·
Maintainers usually reply within 2 days
All issues in blacklanternsecurity/bbot
Similar issues
-
eegprep-lean: set channel types from the Zarr group's channel_typePossibly taken @claude claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
sccn/eegprep#668 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Link Checker ReportOpenBot Type: Bug Type: Documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
speakeasy-api/speakeasy#2159 ·
Maintainers usually reply within 1 day
-
area: ci enhancement perceived difficulty: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Nitjsefnie-Harness-Commons/daedalus#1826 ·
Maintainers usually reply within 1 day