Skip to content

Output attempted address in strict mode #296

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

Conversation

wilhelmklopp
Copy link
Contributor

This is another change on the back of #295 – I made this locally and it helped quite a bit as i was migrating from httpretty to mocket. This way you can see which url the test tried to access, but couldn't.

Was specifically quite helpful in figuring out the querystring issue. Example output:

mocket.exceptions.StrictMocketException: Mocket tried to use the real `socket` module while STRICT mode was active.
Attempted address: slack.com:443
First request line: GET /api/users.list?team_id=T_e2e_correctly_calculates_enterprise1&limit=500 HTTP/1.1
Registered entries:
  ('slack.com', 443):
    Entry(method='GET', schema='https', location=('slack.com', 443), path='/api/users.list', query='')

Feel free to edit the code or make a separate PR if there's a better way to do this. I think the code works fine as-is for http mocking, but haven't tested with any kind of other socket.

Copy link

Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.72%. Comparing base (713ccd6) to head (8b3a706).
Report is 1 commits behind head on better-strict-mode.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           better-strict-mode     #296      +/-   ##
======================================================
+ Coverage               98.71%   98.72%   +0.01%     
======================================================
  Files                      22       22              
  Lines                    1010     1019       +9     
======================================================
+ Hits                      997     1006       +9     
  Misses                     13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mindflayer
Copy link
Owner

mindflayer commented Jun 11, 2025

What if we allow redefining the MocketMode class instead? So you could pass a class that implements what you need. Of course, we would keep the change that makes Mocket sending more information to the function when raising the error.

@wilhelmklopp
Copy link
Contributor Author

ah interesting so like another mode besides strict_mode=True ? i think that would work for me 👍

@mindflayer mindflayer changed the base branch from main to better-strict-mode June 13, 2025 07:29
@mindflayer mindflayer merged commit e2f51b8 into mindflayer:better-strict-mode Jun 13, 2025
11 checks passed
@mindflayer
Copy link
Owner

mindflayer commented Jun 13, 2025

I changed my mind, kept your code and just changed First request line to a more protocol-agnostic Sent data. Hope you won't mind the change.

mindflayer added a commit that referenced this pull request Jun 13, 2025
* Output attempted address in strict mode (#296)
* Update test
* Make it more HTTP-agnostic.

---------

Co-authored-by: Wilhelm Klopp <wilhelmklopp@users.noreply.github.com>
@mindflayer
Copy link
Owner

@wilhelmklopp Here is the release with a better strict mode:
https://pypi.org/project/mocket/3.13.9/

@wilhelmklopp
Copy link
Contributor Author

@mindflayer very exciting, thanks! 🎉

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

Successfully merging this pull request may close these issues.

2 participants