All Questions
96 questions
1
vote
1
answer
55
views
Mock asyncio.sleep to be faster in unittest
I want to mock asyncio.sleep to shorten the delay, e.g. by a factor of 10, to speed up my tests while also trying to surface any possible race conditions or other bugs as a crude sanity check. However ...
4
votes
2
answers
221
views
Using pytest-twisted functions with pytest-asyncio fixtures
I have code that uses Twisted so I've written a test function for it and decorated it with @pytest_twisted.ensureDeferred. The function awaits on some Deferreds. Then, I need to run some aiohttp ...
0
votes
0
answers
244
views
Getting TypeError: 'coroutine' object does not support the asynchronous context manager protocol pytest
I am writing test for upload_payment_slip_file method and getting given above in the title. I saw the related issue but fortunately it did not help me. Seems like mocking enter/exit methods does not ...
0
votes
0
answers
105
views
Python | RuntimeError : Task got Future in attached to a different loop | SqlAlchemy session
The project is based on FastAPI, the database is postgresql, everything is raised via Docker.
I’m writing fixtures for tests, initially the task was such that the implementation at the end of each ...
0
votes
0
answers
130
views
How do I use Playwright (with async methods) and Pytest to create E2E tests?
I'm creating a test suite for E2E tests that validate network requests while navigating and interacting with a website. I'm using Playwright with async and using conftest.py to set up the browser (...
1
vote
1
answer
402
views
pytest: use the same TCP server between tests
I wanted to create a small test program using pytest to setup a TCP server that sends some data and checks the response. When using @pytest.fixture() without defining a scope, the program works fine ...
0
votes
1
answer
620
views
TypeError: 'coroutine' object does not support the asynchronous context manager protocol in pytest_asyncio
I am trying to preform asynchronous testing for a class who perform HTTPS request using aiohttp.ClientSession.
The issue I am having is that when I call async with session.get as response the ...
0
votes
1
answer
182
views
Correct usage of async session on pytest
Given below implementation, I try to test using an asynchronous session. My attempt goes in the following way:
models.py
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import ...
2
votes
2
answers
534
views
FastAPI TestClient not starting lifetime in test
Example code:
import os
import asyncio
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
@asynccontextmanager
async def lifespan(app: FastAPI):
print(f'Lifetime ON {...
0
votes
1
answer
471
views
Async SQLAlchemy in pytest fixture: greenlet_spawn has not been called
So let's assume that I try to retrieve all users for Pytest tests as a fixture:
@pytest_asyncio.fixture(scope="function")
async def test_users(db_session):
async with db_session.begin():
...
0
votes
0
answers
39
views
How to list all futures that are being polled inside specific event loop when running pytest?
I'm running multiple pytest tests.
I have 1 specific test case, which works fine when executed alone, but when large amount of previous tests are being executed, this particular test gets stuck when ...
2
votes
0
answers
707
views
Playwright-Pytest Error: It looks like you are using Playwright Sync API inside the asyncio loop
I am able to run testcases individually using pytest and class,function fixture:
pytest test_fixtures_class.py
But when I am trying to run all classes testcases using:
pytest
I am getting following ...
1
vote
1
answer
158
views
Getting scrapy and pytest to work with AsyncioSelectorReactor
To reproduce my issue
python 3.12.1
scrapy 2.11.2
pytest 8.2.1
In bookspider.py I have:
from typing import Iterable
import scrapy
from scrapy.http import Request
class BookSpider(scrapy.Spider):
...
0
votes
1
answer
649
views
Task was destroyed but it is pending! even after awaiting it
I wrote the following factory fixture that creates a ReconnectingConsumer and then awaits it to stop:
@pytest.fixture
def make_consumer():
async def _make_consumer():
consumer = ...
0
votes
0
answers
339
views
TypeError: object async_generator can't be used in 'await' expression when using pytest async factory fixture
I'm trying to define an async factory fixture that creates a ReconnectingConsumer object and then awaits it to stop, like this:
@pytest.fixture
def make_consumer():
async def _make_consumer():
...