multi_line_output = 3
[tool:pytest]
-addopts = --cov=httpx --cov=tests --cov-report=term-missing
+addopts = --cov=httpx --cov=tests --cov-report=term-missing -rxXs
+markers =
+ copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accodomate e.g. our test setup
--- /dev/null
+import sys
+
+import pytest
+
+import httpx
+
+
+def pytest_configure(config):
+ # Allow to 'import requests' without having to write 'import httpx as requests'.
+ # This means we *could* literally copy-paste Requests test code as-is, if relevant.
+ sys.modules["requests"] = httpx
+
+
+@pytest.fixture(autouse=True)
+def patch_httpx(monkeypatch):
+ """Monkey-patch Requests APIs onto HTTPX."""
+ monkeypatch.setattr(httpx, "session", httpx.Client, raising=False)
--- /dev/null
+"""Test compatibility with the Requests high-level API."""
+import pytest
+
+import requests
+
+
+@pytest.mark.copied_from(
+ "https://github.com/psf/requests/blob/v2.22.0/tests/test_requests.py#L61-L70"
+)
+def test_entrypoints():
+ requests.session
+ requests.session().get
+ requests.session().head
+ requests.get
+ requests.head
+ requests.put
+ requests.patch
+ requests.post
+
+
+@pytest.mark.copied_from(
+ "https://github.com/psf/requests/blob/v2.22.0/tests/test_requests.py#L72",
+ changes=["added noqa comment to silence flake8"],
+)
+@pytest.mark.xfail(
+ reason="PoolManager has no obvious equivalent in HTTPX", raises=ImportError
+)
+def test_poolmanager_entrypoint():
+ # Not really an entry point, but people rely on it.
+ from requests.packages.urllib3.poolmanager import PoolManager # noqa: F401