Skip to content

Refactor test cases that import from private namespace. #2492

Open

Description

@lovelydinosaur

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.

Activity

  1. lovelydinosaur commented on Dec 6, 2022

    @lovelydinosaur
    MemberAuthor

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

  2. lovelydinosaur commented on Dec 30, 2022

    @lovelydinosaur
    MemberAuthor

    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
    
  3. florimondmanca commented on Feb 5, 2023

    @florimondmanca
    Contributor

    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.

  4. lovelydinosaur commented on May 9, 2023

    @lovelydinosaur
    MemberAuthor

    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 (
    
  5. T-256 commented on Jan 16, 2024

    @T-256
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorIssues and PRs related to code refactoring

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions