Skip to content

Test collection fails when using pytest.mark.usefixtures and a test function is a classmethod #3537

@konoufo

Description

@konoufo

This minimal example using django TestCase class causes an error on collection:

from django.test import TestCase
import pytest


@pytest.fixture
def harry_potter(request):
    return 1


@pytest.mark.usefixtures('harry_potter')
class FooTestCase(TestCase):
    @classmethod
    def test_foo(cls):
        assert 1

The output of running pytest is as such:

platform linux -- Python 3.6.5, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
Django settings: project.settings.development (from ini file)
rootdir: /users/username/project/src, inifile: pytest.ini
plugins: django-3.2.1, celery-4.1.1
collected 11 items / 1 errors                                                                                                                                                                                                               

================================================================================================================== ERRORS ===================================================================================================================
_______________________________________________________________________________________________ ERROR collecting tests/fooTestCase.py ________________________________________________________________________________________________
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/runner.py:198: in __init__
    self.result = func()
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/runner.py:419: in <lambda>
    call = CallInfo(lambda: list(collector.collect()), "collect")
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/unittest.py:57: in collect
    transfer_markers(funcobj, cls, module)
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/mark/structures.py:265: in transfer_markers
    store_legacy_markinfo(funcobj, mark)
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/mark/structures.py:248: in store_legacy_markinfo
    setattr(func, mark.name, holder)
E   AttributeError: 'method' object has no attribute 'usefixtures'

OS: Fedora 27
(See log output for everything else)
If no test function is a classmethod it works alright. I don't know if this is a feature. Nothing seems to imply that.
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions