pytest-asyncio

ScopeMismatch when i try to make setup_teardown pytest function

ScopeMismatch when i try to make setup_teardown pytest function Question: 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 …

Total answers: 1

How to test async function using pytest?

How to test async function using pytest? Question: @pytest.fixture def d_service(): c = DService() return c # @pytest.mark.asyncio # tried it too async def test_get_file_list(d_service): files = await d_service.get_file_list(”) print(files) However, it got the following error? collected 0 items / 1 errors =================================== ERRORS ==================================== ________________ ERROR collecting tests/e2e_tests/test_d.py _________________ ……….anaconda3libsite-packagespluggy__init__.py:617: in __call__ return self._hookexec(self, …

Total answers: 2

FastAPI, SQLAlchemy, pytest, unable to get 100% coverage, it doesn't properly collected

FastAPI, SQLAlchemy, pytest, unable to get 100% coverage, it doesn't properly collected Question: I’m trying to build FastAPI application fully covered with test using python 3.9 For this purpose I’ve chosen stack: FastAPI, uvicorn, SQLAlchemy, asyncpg, pytest (+ async, cov plugins), coverage and httpx AsyncClient Here is my minimal requirements.txt All tests run smoothly and …

Total answers: 2

Using @pytest.fixture(scope="module") with @pytest.mark.asyncio

Using @pytest.fixture(scope="module") with @pytest.mark.asyncio Question: I think the example below is a really common use case: create a connection to a database once, pass this connection around to test which insert data pass the connection to a test which verifies the data. Changing the scope of @pytest.fixture(scope=”module”) causes ScopeMismatch: You tried to access the ‘function’ …

Total answers: 3

How to timeout an async test in pytest with fixture?

How to timeout an async test in pytest with fixture? Question: I am testing an async function that might get deadlocked. I tried to add a fixture to limit the function to only run for 5 seconds before raising a failure, but it hasn’t worked so far. Setup: pipenv –python==3.6 pipenv install pytest==4.4.1 pipenv install …

Total answers: 3