Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yanksyoon opened this issue Apr 28, 2024 · 2 comments

Comments

@yanksyoon
Copy link

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
  1. 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
Copy link
Author

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

dashmage added a commit to dashmage/hardware-observer-operator that referenced this issue Apr 29, 2024
When using pytest-8.2.0 with async-0.21.1, func tests
throw an error:

`AttributeError: 'FixtureDef' object has no attribute 'unittest'`

Refer: charmed-kubernetes/pytest-operator#131

Therefore, the pytest version is pinned till the issue is resolved
upstream.
@addyess
Copy link
Member

addyess commented Apr 29, 2024

Resolved now by new pytest-asyncio==0.21.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants