Giter Club home page Giter Club logo

Comments (2)

Colin-b avatar Colin-b commented on September 7, 2024 1

Hello @realsuayip ,

This behavior is already documented.

Considering that the following requests are issued by your code:

  1. http://example.com/test/123
  2. http://example.com/test/123
  3. http://example.com/test/1
  4. http://example.com/test/123

With your example, this would mean the following responses:

  1. 404 (as it matches the regex and it is hasn't been sent yet)
  2. 200 (as it matches the url and it hasn't been sent yet, while the regex was already sent)
  3. 404 (as it only matches the regex)
  4. 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:

  1. 200 (as it matches the url and it is hasn't been sent yet)
  2. 404 (as it matches the regex and it hasn't been sent yet, while the url was already sent)
  3. 404 (as it only matches the regex)
  4. 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.

realsuayip avatar realsuayip commented on September 7, 2024 1

It seems that I have missed the relevant part in documentation. Thanks for the clarification.

from pytest_httpx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.