pytest-socket icon indicating copy to clipboard operation
pytest-socket copied to clipboard

Cache name resolutions

Open twm opened this issue 1 year ago • 2 comments

To avoid resolving the allowed hostnames once per test, cache the results in a shared dict. This should result in one set of resolutions per pytest run (or test worker, under pytest-xdist). I did this in a backward-compatible manner by introducing an optional parameter to the socket_allow_hosts() and normalize_allowed_hosts() functions as they appear to be public API, albeit undocumented.

I also refactored the plugin to use Stash, which was introduced in pytest 7.0.0, rather than set attributes on Config. If you want to keep support for pytest>=6.2.5 I can back that bit out, I just thought it improved clarity.

twm avatar Aug 20 '24 22:08 twm

Code Climate has analyzed commit f2704d50 and detected 0 issues on this pull request.

View more on Code Climate.

qlty-cloud-legacy[bot] avatar Aug 23 '24 00:08 qlty-cloud-legacy[bot]

@miketheman I think I've addressed all your feedback. I settled on monkey patching socket.getaddrinfo() to count the number of calls to ensure the cache works.

Interestingly, it looks like pre-commit.ci's autocommit bypasses workflow approval. (Sorry about the many notifications...)

twm avatar Aug 23 '24 00:08 twm

Thank you for the review!

twm avatar Sep 07 '24 00:09 twm