charmed-kubernetes / pytest-operator

Apache License 2.0
7 stars 13 forks source link

Pytest 8.2.0: AttributeError: 'FixtureDef' object has no attribute 'unittest' when using #131

Closed yanksyoon closed 6 months ago

yanksyoon commented 6 months ago

When using with the most recent version of pytest 8.2.0, asyncio-0.21.1 is used which breaks the fixtures with error: AttributeError: 'FixtureDef' object has no attribute 'unittest'.

To reproduce:

  1. Minimal tox.ini in project root.
    
    # Copyright 2024 Canonical Ltd.
    # See LICENSE file for licensing details.

[tox] skipsdist=True skip_missing_interpreters = True envlist = unit

[vars] src_path = {toxinidir}/src/ tst_path = {toxinidir}/tests/ ;lib_path = {toxinidir}/lib/charms/operator_name_with_underscores all_path = {[vars]src_path} {[vars]tst_path}

[testenv] basepython = python3.10 setenv = PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path} PYTHONBREAKPOINT=ipdb.set_trace PY_COLORS=1 passenv = PYTHONPATH

[testenv:integration] description = Run integration tests pass_env = PYTEST_ADDOPTS deps = pytest pytest-asyncio pytest-operator commands = pytest -v --tb native --log-cli-level=INFO


2. Create test file `tests/integratin/test_asyncio.py`

import logging

import pytest import pytest_asyncio

logger = logging.getLogger(name)

@pytest_asyncio.fixture(name="buggy") async def async_fixture(): logger.info("SETUP FIXTURE") return "buggy"

@pytest.mark.asyncio async def test_buggy(buggy): logger.info("TESTING") print(f"hello {buggy}")



The test will fail.
yanksyoon commented 6 months ago

Btw for anyone that is experiencing the issue - downgrade pytest pytest==8.1.1 to mitigate issue for now.

addyess commented 6 months ago

Resolved now by new pytest-asyncio==0.21.2