respx icon indicating copy to clipboard operation
respx copied to clipboard

Test error in Python 3.12 -Debian

Open NGC2023 opened this issue 1 year ago • 1 comments
trafficstars

Hi, I am getting the following test error while building the package in Debian unstable.

_____________________ ERROR at setup of test_plain_fixture _____________________
file /tmp/pytest-of-yogu/pytest-0/test_respx_mock_fixture0/test_respx_mock_fixture.py, line 8
  def test_plain_fixture(respx_mock):
E       fixture 'respx_mock' not found
>       available fixtures: anyio_backend, anyio_backend_name, anyio_backend_options, autojump_clock, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, event_loop, http_client, http_server, http_server_client, http_server_port, io_loop, mock_clock, monkeypatch, no_cover, nursery, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, some_fixture, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, twisted_greenlet, unused_tcp_port, unused_tcp_port_factory, unused_udp_port, unused_udp_port_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/tmp/pytest-of-yogu/pytest-0/test_respx_mock_fixture0/test_respx_mock_fixture.py:8

I have created a patch to address this error,

--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -3,6 +3,7 @@ def test_respx_mock_fixture(testdir):
         """
         import httpx
         import pytest
+        from respx.plugin import respx_mock
 
         @pytest.fixture
         def some_fixture():

There is a deprecated warning too,

.pybuild/cpython3_3.12_respx/build/tests/test_mock.py::test_proxies
  /usr/lib/python3/dist-packages/httpx/_client.py:671: DeprecationWarning: The 'proxies' argument is now deprecated. Use 'proxy' or 'mounts' instead.
    warnings.warn(message, DeprecationWarning)

Fix for the warning below,

--- a/tests/test_mock.py
+++ b/tests/test_mock.py
@@ -476,14 +476,14 @@ def test_add_remove_targets():
 async def test_proxies():
     with respx.mock:
         respx.get("https://foo.bar/") % dict(json={"foo": "bar"})
-        with httpx.Client(proxies={"https://": "https://1.1.1.1:1"}) as client:
+        with httpx.Client(proxy={"https://": "https://1.1.1.1:1"}) as client:
             response = client.get("https://foo.bar/")
         assert response.json() == {"foo": "bar"}
 
     async with respx.mock:
         respx.get("https://foo.bar/") % dict(json={"foo": "bar"})
         async with httpx.AsyncClient(
-            proxies={"https://": "https://1.1.1.1:1"}
+            proxy={"https://": "https://1.1.1.1:1"}
         ) as client:
             response = await client.get("https://foo.bar/")
         assert response.json() == {"foo": "bar"}

NGC2023 avatar Aug 17 '24 23:08 NGC2023

Thanks, we should address the warnings 👍

About the test_respx_mock_fixture test, it's testing that the pytest respx plugin works by supplying/forcing -p respx when executing, to simulate a proper user environment, without your suggested import.

This probably breaks for you due to where executed, e.g. python path, virtual environment etc

lundberg avatar Sep 02 '24 09:09 lundberg