Skip to content

Getting error "setUpClass should be a classmethod" #597

Closed
@kleptog

Description

@kleptog

Recently some magic was added that tries wrap the setUpClass methods for some reason. Not sure why. In any case, it breaks our testsuite. I've attached a test file to reproduce.

The basic issue is that the the setUpClass raises a skip exception sometimes to cause the methods defined in that class to be skipped. This causes the wrapping code to skip restoring the classmethod, leading to errors later on.

The error is in this code:

_restore_class_methods(cls)
cls.setUpClass()
_disable_class_methods(cls)

If the setUpClass() throws an exception (in this case Skip), the restore is skipped and chaos ensues.

This is a test file that reproduces it:

import pytest
from django.test import SimpleTestCase


class foo(SimpleTestCase):
    @classmethod
    def setUpClass(cls):
        if cls is foo:
            raise pytest.skip("Skip base class")
        super(foo, cls).setUpClass()

    def test_shared_foo(self):
        pass


class bar(foo):
    def test_bar1(self):
        pass


class bar2(foo):
    def test_bar21(self):
        pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions