nofoobar / JobBoard-Fastapi

A job board app using fastapi
https://www.fastapitutorial.com/
179 stars 57 forks source link

Error in pytest #4

Open frchalaoux opened 1 year ago

frchalaoux commented 1 year ago

Hi, I'm testing your super apple but got an error with the pytest in "15 : Unit Testing FastAPI Routes". Can you have a look ?

My repository is : https://github.com/frchalaoux/cleanmysurface

(melange_py310) frchalaoux$ pytest
============================================= test session starts ==============================================
platform darwin -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/frchalaoux/Documents/Drone/RAndD/Dev/cleanmysurface/backend
plugins: anyio-3.5.0
collected 1 item                                                                                               

tests/test_routes/test_users.py F                                                                        [100%]

=================================================== FAILURES ===================================================
_______________________________________________ test_create_user _______________________________________________

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

    def test_create_user(client) -> None:
        """_summary_

        Args:
            client (_type_): _description_
        """
        data = {"username":"testuser","email":"testuser@nofoobar.com","is_active": "True", "password":"testing"}
>       response = client.post("/users/",json.dumps(data))
E       TypeError: TestClient.post() takes 2 positional arguments but 3 were given

tests/test_routes/test_users.py:11: TypeError
=========================================== short test summary info ============================================
FAILED tests/test_routes/test_users.py::test_create_user - TypeError: TestClient.post() takes 2 positional ar...
============================================== 1 failed in 0.15s ===============================================

cheers, François-Régis

PS: I have exactly the same type of errors when I run pytest with your code !

Whateverdoa commented 1 year ago

response = client.post(url="/users/", data=json.dumps(data))

buytfdip commented 1 year ago

response = client.post(url="/users/", data=json.dumps(data))

that fixed it, thanks sir.

FredericoIsaac commented 1 year ago

If reciving this warning:

DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content. warnings.warn(message, DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Use this: response = client.post("/users/", content=json.dumps(data))