Skip to content

Encountered two issues in the code for the chapter 3 / pytest part #2

@TsarSPb

Description

@TsarSPb

Hey guys, thanks for the course, nice job! Have learnt a thing or two so far.

Brought some feedback / issues I encountered in the Chapter 3.

Issue 1 - Getting the AsyncClient.__init__() got an unexpected keyword argument 'app' error when running pytest

Detailed error

    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    /home/tsar/python_venv/fastapi/lib/python3.10/site-packages/anyio/_backends/_asyncio.py:2234: in run_asyncgen_fixture
        fixturevalue: T_Retval = self.get_loop().run_until_complete(
    /usr/lib/python3.10/asyncio/base_events.py:649: in run_until_complete
        return future.result()
    /home/tsar/python_venv/fastapi/lib/python3.10/site-packages/anyio/_backends/_asyncio.py:2226: in _call_in_runner_task
        return await future
    /home/tsar/python_venv/fastapi/lib/python3.10/site-packages/anyio/_backends/_asyncio.py:2193: in _run_tests_and_fixtures
        retval = await coro
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    client = <starlette.testclient.TestClient object at 0x7fb59e68b2e0>

    @pytest.fixture()
    async def async_client(client) -> AsyncGenerator:
    >       async with AsyncClient(app=app, base_url=client.base_url) as ac:
    E       TypeError: AsyncClient.__init__() got an unexpected keyword argument 'app'

    mediaapi/tests/conftest.py:33: TypeError
    ================================================================================ short test summary info ================================================================================
    ERROR mediaapi/tests/routers/test_post.py::test_create_post - TypeError: AsyncClient.__init__() got an unexpected keyword argument 'app'

Downgrading httpx version to httpx==0.27.2 in requirements-dev.txt resolved the issue for me.

Issue 2 - http 200 vs http 201

For me the post requests made from async def test_create_comment (it' in the tests/routers/test_post.py) return http 200, not 201. Haven't tried to pinpoint the cause (could also be a difference between the fastapi or some other package's versions), just switched from

    assert response.status_code == 201

to

    assert response.status_code in [200, 201]

in tests/routers/test_post.py

Can't make a PR since all the course source code is zipped, so just reporting here.

Thanks again!

BR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions