Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative match #177

Open
WojciechMigda opened this issue Jan 31, 2025 · 2 comments
Open

Negative match #177

WojciechMigda opened this issue Jan 31, 2025 · 2 comments

Comments

@WojciechMigda
Copy link

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.

@Colin-b
Copy link
Owner

Colin-b commented Jan 31, 2025

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.

@WojciechMigda
Copy link
Author

WojciechMigda commented Jan 31, 2025

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

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

No branches or pull requests

2 participants