pytest_httpx icon indicating copy to clipboard operation
pytest_httpx copied to clipboard

Negative match

Open WojciechMigda opened this issue 10 months ago • 2 comments

Hi, is there an elegant way to achieve negative match with pytest_httpx? For instance, verify that a header is not present in the request?

A workaround might involve copying existing add_response and modifying it by adding custom assertions in the callback, but I don't feel good about it.

WojciechMigda avatar Jan 31 '25 15:01 WojciechMigda

Hello, there is currently no way of doing response matching based on the fact that a header key does not exists. To check this, you currently need to get the request(s) afterwards and assert that the header key is not present yourself.

This is however something I wouldn't mind adding as a feature, I would need to think of something clean to specify this as people would want to match on value being different as well.

Colin-b avatar Jan 31 '25 15:01 Colin-b

Maybe a general custom matcher, defined as a user-defined callable which accepts httpx.Request?

WojciechMigda avatar Jan 31 '25 16:01 WojciechMigda