Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RabbitMQ service not found when running pytest with poetry #232

Closed
natelastname opened this issue Feb 6, 2025 · 4 comments
Closed

RabbitMQ service not found when running pytest with poetry #232

natelastname opened this issue Feb 6, 2025 · 4 comments

Comments

@natelastname
Copy link

Problem

As the generated README.md suggests, I am running postgres with the command:

docker run -p "5432:5432" -e "POSTGRES_PASSWORD=readapp2" -e "POSTGRES_USER=readapp2" -e "POSTGRES_DB=readapp2" postgres:16.3-bullseye

and then attemping to run pytest via the command poetry run pytest -vv . The problem is that 2/5 of the tests (the ones defined in the file test_rabbit.py) fail because it cannot resolve the ampq url for the rabbitMQ service.

After messing with it a bit, I cannot figure out an easy way to launch an instance of rabbitMQ as a stand-alone container.

Full output


(base) nate@nate-Kudu:~/spyder_projects/readapp/readapp2$ poetry run pytest . -vv
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0 -- /home/nate/.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/bin/python
cachedir: .pytest_cache
rootdir: /home/nate/spyder_projects/readapp/readapp2
configfile: pyproject.toml
plugins: anyio-4.8.0, env-1.1.5, cov-5.0.0
collected 7 items                                                                                                                                                                      

tests/test_db.py::test_db PASSED                                                                                                                                                 [ 14%]
tests/test_echo.py::test_echo PASSED                                                                                                                                             [ 28%]
tests/test_rabbit.py::test_message_publishing ERROR                                                                                                                              [ 42%]
tests/test_rabbit.py::test_message_wrong_exchange ERROR                                                                                                                          [ 57%]
tests/test_readapp2.py::test_health PASSED                                                                                                                                       [ 71%]
tests/test_redis.py::test_setting_value PASSED                                                                                                                                   [ 85%]
tests/test_redis.py::test_getting_value PASSED                                                                                                                                   [100%]

======================================================================================== ERRORS ========================================================================================
______________________________________________________________________ ERROR at setup of test_message_publishing _______________________________________________________________________

self = <Connection: "amqp://guest:******@readapp2-rmq:5672/" at 0x784ad9d4edf0>, client_properties = {}

    @task
    async def connect(
        self, client_properties: Optional[FieldTable] = None,
    ) -> bool:
        if self.is_opened:
            raise RuntimeError("Connection already opened")
    
        ssl_context = self.ssl_context
    
        if ssl_context is None and self.url.scheme == "amqps":
            ssl_context = await self.loop.run_in_executor(
                None, self._get_ssl_context,
            )
            self.ssl_context = ssl_context
    
        log.debug("Connecting to: %s", self)
        try:
>           reader, writer = await asyncio.open_connection(
                self.url.host, self.url.port, ssl=ssl_context,
                **self.__create_connection_kwargs,
            )

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:457: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../miniconda3/lib/python3.12/asyncio/streams.py:48: in open_connection
    transport, _ = await loop.create_connection(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:1078: in create_connection
    infos = await self._ensure_resolved(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:1461: in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
../../../miniconda3/lib/python3.12/asyncio/base_events.py:900: in getaddrinfo
    return await self.run_in_executor(
../../../miniconda3/lib/python3.12/concurrent/futures/thread.py:59: in run
    result = self.fn(*self.args, **self.kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

host = 'readapp2-rmq', port = 5672, family = 0, type = <SocketKind.SOCK_STREAM: 1>, proto = 0, flags = 0

    def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
        """Resolve host and port into list of address info entries.
    
        Translate the host/port argument into a sequence of 5-tuples that contain
        all the necessary arguments for creating a socket connected to that service.
        host is a domain name, a string representation of an IPv4/v6 address or
        None. port is a string service name such as 'http', a numeric port number or
        None. By passing None as the value of host and port, you can pass NULL to
        the underlying C API.
    
        The family, type and proto arguments can be optionally specified in order to
        narrow the list of addresses returned. Passing zero as a value for each of
        these arguments selects the full range of results.
        """
        # We override this function since we want to translate the numeric family
        # and socket type values to enum constants.
        addrlist = []
>       for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
E       socket.gaierror: [Errno -2] Name or service not known

../../../miniconda3/lib/python3.12/socket.py:976: gaierror

The above exception was the direct cause of the following exception:

anyio_backend = 'asyncio', request = <SubRequest 'test_exchange' for <Function test_message_publishing>>, args = ()
kwargs = {'test_exchange_name': '1cd4c981028b42628b327156c64487d5', 'test_rmq_pool': <aio_pika.pool.Pool object at 0x784ad9dfde70>}
local_func = <function test_exchange at 0x784ada1a6f20>, backend_name = 'asyncio', backend_options = {}, runner = <anyio._backends._asyncio.TestRunner object at 0x784ada00dd60>

    def wrapper(
        *args: Any, anyio_backend: Any, request: SubRequest, **kwargs: Any
    ) -> Any:
        # Rebind any fixture methods to the request instance
        if (
            request.instance
            and ismethod(func)
            and type(func.__self__) is type(request.instance)
        ):
            local_func = func.__func__.__get__(request.instance)
        else:
            local_func = func
    
        backend_name, backend_options = extract_backend_and_options(anyio_backend)
        if has_backend_arg:
            kwargs["anyio_backend"] = anyio_backend
    
        if has_request_arg:
            kwargs["request"] = request
    
        with get_runner(backend_name, backend_options) as runner:
            if isasyncgenfunction(local_func):
>               yield from runner.run_asyncgen_fixture(local_func, kwargs)

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/pytest_plugin.py:98: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2234: in run_asyncgen_fixture
    fixturevalue: T_Retval = self.get_loop().run_until_complete(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:686: in run_until_complete
    return future.result()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2226: in _call_in_runner_task
    return await future
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2193: in _run_tests_and_fixtures
    retval = await coro
tests/conftest.py:140: in test_exchange
    async with test_rmq_pool.acquire() as conn:
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:147: in __aenter__
    self.item = await self.pool._get()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:104: in _get
    return await self._create_item()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:92: in _create_item
    item = await self.__constructor(*self.__constructor_args)
readapp2/services/rabbit/lifespan.py:38: in get_channel
    async with connection_pool.acquire() as connection:
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:147: in __aenter__
    self.item = await self.pool._get()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:104: in _get
    return await self._create_item()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:92: in _create_item
    item = await self.__constructor(*self.__constructor_args)
readapp2/services/rabbit/lifespan.py:22: in get_connection
    return await aio_pika.connect_robust(str(settings.rabbit_url))
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:334: in connect_robust
    await connection.connect(timeout=timeout)
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:180: in connect
    await self.__fail_fast_future
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:135: in __connection_factory
    await Connection.connect(self, self.__connect_timeout)
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/connection.py:125: in connect
    self.transport = await UnderlayConnection.connect(
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/abc.py:679: in connect
    connection = await cls.make_connection(
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/abc.py:667: in make_connection
    connection: aiormq.abc.AbstractConnection = await asyncio.wait_for(
../../../miniconda3/lib/python3.12/asyncio/tasks.py:520: in wait_for
    return await fut
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:920: in connect
    await connection.connect(client_properties or {})
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/base.py:164: in wrap
    return await self.create_task(func(self, *args, **kwargs))
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/abc.py:44: in __inner
    return await self.task
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Connection: "amqp://guest:******@readapp2-rmq:5672/" at 0x784ad9d4edf0>, client_properties = {}

    @task
    async def connect(
        self, client_properties: Optional[FieldTable] = None,
    ) -> bool:
        if self.is_opened:
            raise RuntimeError("Connection already opened")
    
        ssl_context = self.ssl_context
    
        if ssl_context is None and self.url.scheme == "amqps":
            ssl_context = await self.loop.run_in_executor(
                None, self._get_ssl_context,
            )
            self.ssl_context = ssl_context
    
        log.debug("Connecting to: %s", self)
        try:
            reader, writer = await asyncio.open_connection(
                self.url.host, self.url.port, ssl=ssl_context,
                **self.__create_connection_kwargs,
            )
    
            frame_receiver = FrameReceiver(reader)
        except OSError as e:
>           raise AMQPConnectionError(*e.args) from e
E           aiormq.exceptions.AMQPConnectionError: [Errno -2] Name or service not known

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:464: AMQPConnectionError
____________________________________________________________________ ERROR at setup of test_message_wrong_exchange _____________________________________________________________________

self = <Connection: "amqp://guest:******@readapp2-rmq:5672/" at 0x784ad93d2fd0>, client_properties = {}

    @task
    async def connect(
        self, client_properties: Optional[FieldTable] = None,
    ) -> bool:
        if self.is_opened:
            raise RuntimeError("Connection already opened")
    
        ssl_context = self.ssl_context
    
        if ssl_context is None and self.url.scheme == "amqps":
            ssl_context = await self.loop.run_in_executor(
                None, self._get_ssl_context,
            )
            self.ssl_context = ssl_context
    
        log.debug("Connecting to: %s", self)
        try:
>           reader, writer = await asyncio.open_connection(
                self.url.host, self.url.port, ssl=ssl_context,
                **self.__create_connection_kwargs,
            )

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:457: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../miniconda3/lib/python3.12/asyncio/streams.py:48: in open_connection
    transport, _ = await loop.create_connection(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:1078: in create_connection
    infos = await self._ensure_resolved(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:1461: in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
../../../miniconda3/lib/python3.12/asyncio/base_events.py:900: in getaddrinfo
    return await self.run_in_executor(
../../../miniconda3/lib/python3.12/concurrent/futures/thread.py:59: in run
    result = self.fn(*self.args, **self.kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

host = 'readapp2-rmq', port = 5672, family = 0, type = <SocketKind.SOCK_STREAM: 1>, proto = 0, flags = 0

    def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
        """Resolve host and port into list of address info entries.
    
        Translate the host/port argument into a sequence of 5-tuples that contain
        all the necessary arguments for creating a socket connected to that service.
        host is a domain name, a string representation of an IPv4/v6 address or
        None. port is a string service name such as 'http', a numeric port number or
        None. By passing None as the value of host and port, you can pass NULL to
        the underlying C API.
    
        The family, type and proto arguments can be optionally specified in order to
        narrow the list of addresses returned. Passing zero as a value for each of
        these arguments selects the full range of results.
        """
        # We override this function since we want to translate the numeric family
        # and socket type values to enum constants.
        addrlist = []
>       for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
E       socket.gaierror: [Errno -2] Name or service not known

../../../miniconda3/lib/python3.12/socket.py:976: gaierror

The above exception was the direct cause of the following exception:

anyio_backend = 'asyncio', request = <SubRequest 'test_exchange' for <Function test_message_wrong_exchange>>, args = ()
kwargs = {'test_exchange_name': '74502e149edc4d7f8e65679f6dad990c', 'test_rmq_pool': <aio_pika.pool.Pool object at 0x784ad8cdc970>}
local_func = <function test_exchange at 0x784ada1a6f20>, backend_name = 'asyncio', backend_options = {}, runner = <anyio._backends._asyncio.TestRunner object at 0x784ada00dd60>

    def wrapper(
        *args: Any, anyio_backend: Any, request: SubRequest, **kwargs: Any
    ) -> Any:
        # Rebind any fixture methods to the request instance
        if (
            request.instance
            and ismethod(func)
            and type(func.__self__) is type(request.instance)
        ):
            local_func = func.__func__.__get__(request.instance)
        else:
            local_func = func
    
        backend_name, backend_options = extract_backend_and_options(anyio_backend)
        if has_backend_arg:
            kwargs["anyio_backend"] = anyio_backend
    
        if has_request_arg:
            kwargs["request"] = request
    
        with get_runner(backend_name, backend_options) as runner:
            if isasyncgenfunction(local_func):
>               yield from runner.run_asyncgen_fixture(local_func, kwargs)

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/pytest_plugin.py:98: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2234: in run_asyncgen_fixture
    fixturevalue: T_Retval = self.get_loop().run_until_complete(
../../../miniconda3/lib/python3.12/asyncio/base_events.py:686: in run_until_complete
    return future.result()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2226: in _call_in_runner_task
    return await future
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2193: in _run_tests_and_fixtures
    retval = await coro
tests/conftest.py:140: in test_exchange
    async with test_rmq_pool.acquire() as conn:
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:147: in __aenter__
    self.item = await self.pool._get()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:104: in _get
    return await self._create_item()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:92: in _create_item
    item = await self.__constructor(*self.__constructor_args)
readapp2/services/rabbit/lifespan.py:38: in get_channel
    async with connection_pool.acquire() as connection:
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:147: in __aenter__
    self.item = await self.pool._get()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:104: in _get
    return await self._create_item()
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/pool.py:92: in _create_item
    item = await self.__constructor(*self.__constructor_args)
readapp2/services/rabbit/lifespan.py:22: in get_connection
    return await aio_pika.connect_robust(str(settings.rabbit_url))
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:334: in connect_robust
    await connection.connect(timeout=timeout)
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:180: in connect
    await self.__fail_fast_future
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/robust_connection.py:135: in __connection_factory
    await Connection.connect(self, self.__connect_timeout)
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/connection.py:125: in connect
    self.transport = await UnderlayConnection.connect(
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/abc.py:679: in connect
    connection = await cls.make_connection(
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aio_pika/abc.py:667: in make_connection
    connection: aiormq.abc.AbstractConnection = await asyncio.wait_for(
../../../miniconda3/lib/python3.12/asyncio/tasks.py:520: in wait_for
    return await fut
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:920: in connect
    await connection.connect(client_properties or {})
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/base.py:164: in wrap
    return await self.create_task(func(self, *args, **kwargs))
../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/abc.py:44: in __inner
    return await self.task
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Connection: "amqp://guest:******@readapp2-rmq:5672/" at 0x784ad93d2fd0>, client_properties = {}

    @task
    async def connect(
        self, client_properties: Optional[FieldTable] = None,
    ) -> bool:
        if self.is_opened:
            raise RuntimeError("Connection already opened")
    
        ssl_context = self.ssl_context
    
        if ssl_context is None and self.url.scheme == "amqps":
            ssl_context = await self.loop.run_in_executor(
                None, self._get_ssl_context,
            )
            self.ssl_context = ssl_context
    
        log.debug("Connecting to: %s", self)
        try:
            reader, writer = await asyncio.open_connection(
                self.url.host, self.url.port, ssl=ssl_context,
                **self.__create_connection_kwargs,
            )
    
            frame_receiver = FrameReceiver(reader)
        except OSError as e:
>           raise AMQPConnectionError(*e.args) from e
E           aiormq.exceptions.AMQPConnectionError: [Errno -2] Name or service not known

../../../.cache/pypoetry/virtualenvs/readapp2-vunyLE_l-py3.12/lib/python3.12/site-packages/aiormq/connection.py:464: AMQPConnectionError
=============================================================================== short test summary info ================================================================================
ERROR tests/test_rabbit.py::test_message_publishing - aiormq.exceptions.AMQPConnectionError: [Errno -2] Name or service not known
ERROR tests/test_rabbit.py::test_message_wrong_exchange - aiormq.exceptions.AMQPConnectionError: [Errno -2] Name or service not known
============================================================================= 5 passed, 2 errors in 1.02s ==============================================================================
@natelastname
Copy link
Author

I'll note that this might not be an essential fix since debugging via container still works.
It could potentially be resolved tweaking the README.

@s3rius
Copy link
Owner

s3rius commented Feb 7, 2025

I'd suggest you to run the whole test-suite with docker-compose.

To do so you can just run

docker-compose run --build --rm api pytest -vv .

This command will work for sure, because that's how I test if all configurations work. The only note here is that you might want to update env variables.

@natelastname
Copy link
Author

I'd suggest you to run the whole test-suite with docker-compose.

To do so you can just run

docker-compose run --build --rm api pytest -vv .

This command will work for sure, because that's how I test if all configurations work. The only note here is that you might want to update env variables.

Can confirm that this method still works.

A bit of background in case anyone else runs into this issue- The reason I wanted to run the tests using Poetry is because I wanted to have my personal .pdbrc file loaded during PDB debugging sessions. This provides the ability to use QOL features such as tab completion and aliases in PDB. I found out that it is possible to achieve this via modifying the Dockerfile:

FROM python:3.11.4-slim-bullseye AS prod
RUN apt-get update && apt-get install -y \
  gcc \
  && rm -rf /var/lib/apt/lists/*


RUN pip install poetry==1.8.2

# Configuring poetry
RUN poetry config virtualenvs.create false
RUN poetry config cache-dir /tmp/poetry_cache

# Copying requirements of a project
COPY pyproject.toml poetry.lock /app/src/

######################################
# Copy dotfiles
COPY dotfiles/.pdbrc dotfiles/.pdbrc.py /root
######################################

WORKDIR /app/src

# Installing requirements
RUN --mount=type=cache,target=/tmp/poetry_cache poetry install --only main
# Removing gcc
RUN apt-get purge -y \
  gcc \
  && rm -rf /var/lib/apt/lists/*

# Copying actuall application
COPY . /app/src/
RUN --mount=type=cache,target=/tmp/poetry_cache poetry install --only main

CMD ["/usr/local/bin/python", "-m", "readapp2"]

FROM prod AS dev

RUN --mount=type=cache,target=/tmp/poetry_cache poetry install

@s3rius
Copy link
Owner

s3rius commented Feb 17, 2025

Closing the issues, because you found a way to solve it. Thanks for your response.

@s3rius s3rius closed this as completed Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants