Comments (2)
Hello @realsuayip ,
This behavior is already documented.
Considering that the following requests are issued by your code:
- http://example.com/test/123
- http://example.com/test/123
- http://example.com/test/1
- http://example.com/test/123
With your example, this would mean the following responses:
- 404 (as it matches the regex and it is hasn't been sent yet)
- 200 (as it matches the url and it hasn't been sent yet, while the regex was already sent)
- 404 (as it only matches the regex)
- 200 (as it matches both url and regex and url was the latest registered)
Unless you expect the absolute URL to be issued only once, changing the order of registration would NOT fix this issue as this would mean the following responses:
- 200 (as it matches the url and it is hasn't been sent yet)
- 404 (as it matches the regex and it hasn't been sent yet, while the url was already sent)
- 404 (as it only matches the regex)
- 404 (as it matches both url and regex and regex was the latest registered)
To properly fix your issue, your regex should exclude the specific URL it shouldn't match.
To come back on your proposal:
I understand that, in your use case, you provide only 2 response, one being an absolute match and the other being a regex.
It is indeed easy to imagine that we could make a deterministic choice and always chose the absolute match.
However this might not be the expected behavior for everyone, moreover we can imagine use case with more than one regex matching the same url.
Making it even harder to know what is the expected behavior for the user.
In any case, I am always eager to enhance the documentation to avoid unexpected behavior.
Do you have any proposal as to how this could be achieved?
Thanks again
from pytest_httpx.
It seems that I have missed the relevant part in documentation. Thanks for the clarification.
from pytest_httpx.
Related Issues (20)
- Matching the `Authorization` header correctly while another parameter doesn't match causes a very confusing error message HOT 2
- Do you plan on putting back support for Python 3.8? HOT 5
- Allow to record and store requests+responses HOT 1
- Allow to add responses based on a file content
- How can I test if the request is being proxied? HOT 4
- httpx does not read the response if an event_hook raises an exception HOT 2
- How can I send multiple responses matching the same request? HOT 3
- Custom Async Client's Transport is not used HOT 7
- Ability to fail a test case if unexpected requests are received and code is swallowing exceptions HOT 4
- support for python 3.8 HOT 2
- Switch from setup.py to a build library HOT 1
- pytest_httpx breaks httpx timeout logic HOT 2
- Support for pytest 8.x.x HOT 2
- `HTTPXMock` context manager HOT 3
- Introduce decorators to setup httpx_mock
- support query param matcher
- Allow to match on different kind of timeouts
- Can one add mocked responses *after* creating the HTTPX client? HOT 2
- The following responses are mocked but not requested HOT 5
- How to mock and test request with content passed as byte iterator
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest_httpx.