Skip to main content

All 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 ...
Joe C.'s user avatar
  • 491
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 ...
wRAR's user avatar
  • 25.6k
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 ...
haku's user avatar
  • 85
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 ...
Yauheni Pryts's user avatar
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 (...
Matt's user avatar
  • 27
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 ...
Quinn Van den Broucke's user avatar
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 ...
Yonatan Levin's user avatar
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 ...
Bruno Lobo's user avatar
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 {...
WebOrCode's user avatar
  • 7,322
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(): ...
Suoslex's user avatar
  • 41
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 ...
Grzegorz Limanówka's user avatar
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 ...
DevTestSecOps's user avatar
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): ...
Henry Dashwood's user avatar
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 = ...
asant-leitha's user avatar
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(): ...
asant-leitha's user avatar

15 30 50 per page
1
2 3 4 5
7