pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.13k stars 2.69k forks source link

PyTest not getting the response when testing a Django endpoint firing a celery shared task asynchronously #8288

Closed tawanda14 closed 3 years ago

tawanda14 commented 3 years ago

The Issue

I have a Django application running in Docker and I am trying to implement unit tests using pytest but I am facing an issue when testing an endpoint that fires celery task, the test is not getting the response from the endpoint, I am hitting the endpoint using API client


The Code

The fixture

@pytest.fixture
def client():
return APIClient()

The Test Class and Function

@pytest.mark.django_db class TestSendfit: async def test_sendfit_post(self, client): sendfit_data = { "name": "Test Name", "age": 1000, "gender": "male", "email": "test@gmail.com", "country": "ZW", "preferences": ["hiit", "yoga"] } response = client.post(SENDFIT_URL, data=sendfit_data) assert response.status_code == status.HTTP_201_CREATED

Screenshot 2021-01-28 at 08 50 35 Screenshot 2021-01-28 at 08 50 41

I hope you can assist

Screenshot 2021-01-28 at 08 49 17 Screenshot 2021-01-28 at 08 49 32 Screenshot 2021-01-28 at 08 49 39
bluetech commented 3 years ago

It is hard to say what is the problem. I suggest attaching a debugger and seeing what happens when the test is executed.

Zac-HD commented 3 years ago

Closing as inactive.