gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module

Home Page:https://httpretty.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnmockedError to actually display which URL failed?

andreas-bergstrom opened this issue · comments

Is there any way through configuration to have UnmockedError display which URL that it's thrown on? Or would it be OK if I made a PR for this behaviour?

Hello @andreas-bergstrom please feel free to open a PR, I'll merge it as soon as I can

This feature will demand some good deal of work, I'm glad to give priority to this if more people show interest, or as soon as I have time for it.

We just had the need for this while running tests in a Django app. Django failed to connect to the DB host. If we knew the URL we could register the URI.

Is there some sort of host whitelist we could use in our case?

We just had the need for this while running tests in a Django app. Django failed to connect to the DB host. If we knew the URL we could register the URI.

Is there some sort of host whitelist we could use in our case?

No whitelist support for now.

OMG I need this. Why is this request closed? What's the workaround, besides putting print() statements in the middle of the code (httpretty/core.py line 556)?

I'm also in the same situation again. Knowing the URL of the failed request would help a lot.

@instantlinux and @sauloperez thanks for bumping this. I'm reopening the ticket to investigate and find a solution

Great! I'd love to help with an implementation but I'm afraid I will only have room for code reviews in the upcoming weeks.

This has been fixed in the release 1.1.0

image

Besides displaying the mismatched url in the UnmockedError exception you can also configure HTTPretty to print debug logs for every request.

Via the logging module:

import logging

logging.getLogger("httpretty.core").setLevel(logging.DEBUG)

When activating httpretty (verbose=True)

import httpretty

httpretty.enable(verbose=True)

# or pass to decorators
@httpretty.activate(verbose=True)

@andreas-bergstrom, @sauloperez and @instantlinux please let me know if this is enough to solve your issues.