Pytest-django: cls.setUpClass () -> TypeError: الكائن "NoneType" غير قابل للاستدعاء

تم إنشاؤها على ٤ يوليو ٢٠١٨  ·  7تعليقات  ·  مصدر: pytest-dev/pytest-django

    @pytest.fixture(autouse=True, scope='class')
    def _django_setup_unittest(request, django_db_blocker):
        """Setup a django unittest, internal to pytest-django."""
        if django_settings_is_configured() and is_django_unittest(request):
            request.getfixturevalue('django_test_environment')
            request.getfixturevalue('django_db_setup')

            django_db_blocker.unblock()

            cls = request.node.cls

            # implement missing (as of 1.10) debug() method for django's TestCase
            # see pytest-dev/pytest-django#406
            def _cleaning_debug(self):
                testMethod = getattr(self, self._testMethodName)
                skipped = (
                    getattr(self.__class__, "__unittest_skip__", False) or
                    getattr(testMethod, "__unittest_skip__", False))

                if not skipped:
                    self._pre_setup()
                super(cls, self).debug()
                if not skipped:
                    self._post_teardown()

            cls.debug = _cleaning_debug

            _restore_class_methods(cls)
>           cls.setUpClass()
E           TypeError: 'NoneType' object is not callable

ربما تتعلق بـ: https :

اقامة:

platform linux -- Python 3.6.5, pytest-3.6.2, py-1.5.4, pluggy-0.6.0 -- /usr/local/bin/python
plugins: django-3.3.2, cov-2.5.1, celery-4.2.0

أعتقد أنه مرتبط بالترقية:

pytest-django==3.3.0 -> 3.3.2
pytest==3.6.1 -> 3.6.2

تحرير: أختبر الدرجة السفلية إلى pytest-django==3.3.0 و pytest==3.6.1 ويعمل الاختبار بشكل جيد.

bug

التعليق الأكثر فائدة

وهو ناتج عن 8a526433a4c601a3e17ce0c90d231dd91a7e7b5b.

استخدم الاختبار التالي:

class TestUnittestMethods:
    def test_setUpClass_new(self, django_testdir):
        django_testdir.create_test_module('''
            from django.test import testcases

            class BaseCMSTestCase:
                pass

            class CMSTestCase(BaseCMSTestCase, testcases.TestCase):
                pass

            class FooBarTestCase(testcases.TestCase):
                <strong i="7">@classmethod</strong>
                def setUpClass(cls):
                    super().setUpClass()

            class TestContact(CMSTestCase, FooBarTestCase):

                def test_noop(self):
                    pass
        ''')

        result = django_testdir.runpytest_subprocess('-v')
        result.stdout.fnmatch_lines([
            "*test_noop PASSED*",
        ])
        assert result.ret == 0

/ ccadamchainz

ال 7 كومينتر

لقد بحثت في هذا أبعد من ذلك. أتيت إلى رمز الاختبار المبسط لإعادة إنتاج الخطأ:

from django.test import testcases
from cms.test_utils.testcases import CMSTestCase

class FooBarTestCase(testcases.TestCase):
    <strong i="6">@classmethod</strong>
    def setUpClass(cls):
        super().setUpClass()

class TestContact(CMSTestCase, FooBarTestCase):

    def test_noop(self):
        print("OK?!?")
        return

ليس لدي وقت لإجراء المزيد من التحقيق في الوقت الحالي :(

وهو ناتج عن 8a526433a4c601a3e17ce0c90d231dd91a7e7b5b.

استخدم الاختبار التالي:

class TestUnittestMethods:
    def test_setUpClass_new(self, django_testdir):
        django_testdir.create_test_module('''
            from django.test import testcases

            class BaseCMSTestCase:
                pass

            class CMSTestCase(BaseCMSTestCase, testcases.TestCase):
                pass

            class FooBarTestCase(testcases.TestCase):
                <strong i="7">@classmethod</strong>
                def setUpClass(cls):
                    super().setUpClass()

            class TestContact(CMSTestCase, FooBarTestCase):

                def test_noop(self):
                    pass
        ''')

        result = django_testdir.runpytest_subprocess('-v')
        result.stdout.fnmatch_lines([
            "*test_noop PASSED*",
        ])
        assert result.ret == 0

/ ccadamchainz

يبدو أن 625 لإصلاحه ، لكنه ليس واضحًا بالنسبة لي حاليًا.

حسنًا!

يبدو أن pytest إصلاح هذا؟!؟

لأن المزيج يبدو أنه يعمل:

بيتيست- دجانجو == 3.3.2
بيتيست == 3.6.3

على الجانب الآخر: لم أر أي معلومات ذات صلة بهذا في https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst#pytest -363-2018-07-04

لست متأكدًا من أن pytest كان بإمكانه إصلاح هذا المنبع ، لأنه متأثر تمامًا برمز داخل pytest-django.

تضمين التغريدة
مثير للاهتمام .. سيكون من الرائع إذا استطعت تقسيمه إلى جزأين ، على سبيل المثال ، ارتكاب pytest ، إذا كنت تعتقد حقًا أنه مرتبط به.

(تأكد أيضًا من عدم استخدام # 625 بطريق الخطأ ، بالطبع ؛))

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات