Questions tagged [pytest-asyncio]

pytest-asyncio is a pytest plugin that facilitates testing asyncio code by providing helper fixtures and markers.

pytest-asyncio is a pytest plugin that provides several fixtures and markers that help testing asyncio code more easily. These help for example to test asyncio event loops, or to use test functions as asyncio coroutines.

Reference:

82 questions
0
votes
0 answers

How to setup pytest for Sanic & Tortoise with test database?

I am trying to use sanic-testing but i can't find example and how no idea how to setup this with test database (e.g. sqlite in memory). I was tried create test database and connect tortoise to it on other fixtures and add to the app listeners which…
0
votes
0 answers

Testing Django API route with internal async call

I have a Django Rest Framework based API with some routes calling async methods (using Celery). Like so : class MyList(ListCreateAPIView, DestroyModelMixin): def post(self, request, format=None): # Asynchronous call using Celery shared…
Beinje
  • 572
  • 3
  • 18
0
votes
0 answers

FastAPI testing an endpoint over a large dataset async with pytest

I have a fairly large dataset that I would like to use for testing a FastAPI endpoint. The issue I am having is that tests take a really long time to run. I am not sure if I have parameterized my tests correctly or if I have async setup correctly. #…
kwehmeyer
  • 63
  • 8
0
votes
1 answer

SQLAlchemy - Pytest - One or more mappers failed to initialize - can't proceed with initialization of other mappers

I am trying to create a DB with user and project tables having a many-to-many relation. A user can be a part of many projects and a project can have many users. I created the models for the user, project and the association tables and am able to…
Vishal
  • 1
0
votes
1 answer

ScopeMismatch when i try to make setup_teardown pytest function

My goal is to create a fixture that will run once at the beginning of the class function test and initialize the attributes I need in self. To do this, I created a fixture with the scope of the class and applied it directly to the class. To solve…
mdar
  • 1
  • 2
0
votes
1 answer

how to unit test an async function in python with pytest-asyncio?

I have an async function that makes a request to the Tenor API. The function gets called/awaited in another function, r.status_code == 200 is True and the function returns the specified gif as a str, but when trying to test the function it no longer…
0
votes
1 answer

RuntimeWarning: coroutine was never awaited in tests

i'm trying to mock an async function that is being called inside of a fastapi endpoint but i'm getting the runtime warning that the coroutine _ was never awaited. src.api.endpoint.py from ..create_utils import helper_function Router =…
pjr4lph
  • 1
  • 2
0
votes
1 answer

Pytest session scoped fixture is calculated several times

I have following structure of tests: tests |__element | |__test_create.py | |__test_delete.py | |__test_get.py | |__test_recover.py | |__test_update.py |__conftest.py I have fixture in conftest.py which must take the same value throughout the…
Prosto_Oleg
  • 322
  • 3
  • 13
0
votes
1 answer

Can we run pytest for a single API hit?

Error : E RuntimeError: Task cb=[_run_until_complete_cb() at…
0
votes
0 answers

Why is my assert_called_once_with giving different ids when calling a mocked async method?

I am struggling with an assert_called_once_with call when mocking an async method in a class. I have the following code that needs to be tested : In class_under_test.py : class ClassUnderTest(): def func_to_be_tested(self, x, y): …
0
votes
1 answer

How to set timeout setting for python-firestore AsyncClient?

I'm using google.cloud.firestore with Async Client, and I want to add timeout setting for adding documents but I can't somehow... Versions Python: 3.9.7 google-cloud-firestore: ">=2.1.0" API framework: fastapi: "^0.70.0" pytest:…
0
votes
1 answer

speed up test with asyncio

Here is my code @pytest.mark.asyncio async def test_async(): res = [] for file_id in range(100): result = await get_files_async(file_id) res.append(result) assert res == [200 for _ in range(100)] async def…
Jeffrey S.
  • 33
  • 6
0
votes
1 answer

Pytest-asyncio not moving to next statement when using with pyppeteer

I am trying to run Pyppeteer with pytest but after launching chromium it's not going to the next statement. import asyncio import pytest from pyppeteer import launch @pytest.mark.asyncio async def test_BackendWeb(): browser = await…
Manish Saini
  • 5
  • 1
  • 3
0
votes
1 answer

Pytest a function which invokes asyncio coroutines

I am trying to write a unit testcase using mock and pytest-asyncio. I have a normal function launching an asyncio coroutine using asyncio.run. [Using python3.7] import asyncio async def sample_async(arg2): # do something proc = await…
SKP
  • 33
  • 6
0
votes
1 answer

Running an asyncio server from a pytest fixture

I'm trying to run a server using asyncio in a pytest fixture @pytest.fixture(autouse=True) @pytest.mark.asyncio async def start_endpoints( endpoint1: ServerEndpoint, endpoint2: ServerEndpoint ): pool = ThreadPoolExecutor(max_workers=2) …
Antonio Santoro
  • 827
  • 1
  • 11
  • 29