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

UnmockedError to actually display which URL failed? #388

Closed
andreas-bergstrom opened this issue Jan 13, 2020 · 9 comments
Closed

UnmockedError to actually display which URL failed? #388

andreas-bergstrom opened this issue Jan 13, 2020 · 9 comments

Comments

@andreas-bergstrom
Copy link

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?

@gabrielfalcao
Copy link
Owner

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

@gabrielfalcao
Copy link
Owner

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.

@sauloperez
Copy link

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?

@gabrielfalcao
Copy link
Owner

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.

@instantlinux
Copy link

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)?

@sauloperez
Copy link

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

@gabrielfalcao
Copy link
Owner

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

@gabrielfalcao gabrielfalcao reopened this May 11, 2021
@sauloperez
Copy link

sauloperez commented May 11, 2021

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.

gabrielfalcao added a commit that referenced this issue May 11, 2021
@httpretty.activate(verbose=True)
httpretty.enable(verbose.True)
etc.

Another option is to set the logger level manually

import logging

from httpretty.core import logger

logger.setLevel(logging.DEBUG)
@gabrielfalcao
Copy link
Owner

gabrielfalcao commented May 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants