httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Refactor test cases that import from private namespace.

Open lovelydinosaur opened this issue 2 years ago • 5 comments
trafficstars

We have some test cases that import from private namespace inside httpx.

This is clearly a code-smell, because our test cases ought to be tests against our public API, rather than testing implementation details. Perhaps there's some cases where it's a necessary hack, but... perhaps not?

It'd be worthwhile reviewing if we're able to remove all the cases where we're doing this. I'd suggest that any pull requests resolving this are handled on a one-module-at-a-time basis.

lovelydinosaur avatar Dec 06 '22 11:12 lovelydinosaur

Similar... can we also avoid/drop uses of mock.patch(...)?

lovelydinosaur avatar Dec 06 '22 12:12 lovelydinosaur

Reminder to self...

Cases currently still left are these:

$ grep -r "from httpx" ./tests/*
./tests/client/test_proxies.py:from httpx._utils import URLPattern
./tests/conftest.py:from httpx import URL
./tests/conftest.py:    from httpx._transports.asgi import _Receive, _Send
./tests/test_decoders.py:from httpx._compat import brotli
./tests/test_decoders.py:from httpx._decoders import ByteChunker, LineDecoder, TextChunker, TextDecoder
./tests/test_exceptions.py:from httpx._transports.default import HTTPCORE_EXC_MAP
./tests/test_exported_members.py:from httpx import __all__ as exported_members
./tests/test_main.py:from httpx import main
./tests/test_main.py:    from httpx._main import main  # noqa: F811
./tests/test_multipart.py:from httpx._content import encode_request
./tests/test_utils.py:from httpx._utils import (
./tests/utils.py:from httpx import _utils

lovelydinosaur avatar Dec 30 '22 19:12 lovelydinosaur

I pushed a bunch of PRs which get most of the remaining refactoring done.

The last bits are in test/test_utils.py, which unit test actual utility functions that I don't think are easy or relevant to test through public API.

florimondmanca avatar Feb 05 '23 13:02 florimondmanca

Follow up from my previous comment...

$ grep -r "from httpx" ./tests/*
./tests/client/test_proxies.py:from httpx._utils import URLPattern
./tests/test_utils.py:from httpx._utils import (

lovelydinosaur avatar May 09 '23 10:05 lovelydinosaur

Only test_utils.py imports these private namespaces:

  • URLPattern
  • get_ca_bundle_from_env
  • get_environment_proxies
  • #3064
  • #3063
  • #3061
  • #3062

T-256 avatar Jan 16 '24 07:01 T-256