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

cls.setUpClass() -> TypeError: 'NoneType' object is not callable #624

Closed
jedie opened this issue Jul 4, 2018 · 7 comments
Closed

cls.setUpClass() -> TypeError: 'NoneType' object is not callable #624

jedie opened this issue Jul 4, 2018 · 7 comments
Labels

Comments

@jedie
Copy link

jedie commented Jul 4, 2018

    @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

Maybe related to: #598 ?!?

setup:

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

Think it's related to the upgrade:

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

EDIT: I test the down grade to pytest-django==3.3.0 and pytest==3.6.1 and the test runs fine.

@jedie
Copy link
Author

jedie commented Jul 4, 2018

I've looked into this further. I come to the simplified test code to reproduce the error:

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

class FooBarTestCase(testcases.TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()

class TestContact(CMSTestCase, FooBarTestCase):

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

I don't have time to investigate any further right now :(

@blueyed
Copy link
Contributor

blueyed commented Jul 4, 2018

It is caused by 8a52643.

Used the following test:

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):
                @classmethod
                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

/cc @adamchainz

@blueyed
Copy link
Contributor

blueyed commented Jul 4, 2018

#625 appears to fix it, but it's not really clear to me currently.

blueyed added a commit to blueyed/pytest-django that referenced this issue Jul 4, 2018
@jedie
Copy link
Author

jedie commented Jul 20, 2018

Hm!

It seems that pytest fix this?!?

Because the combination seems to work:

pytest-django==3.3.2
pytest==3.6.3

On the other side: i didn't see any related information for this in https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst#pytest-363-2018-07-04

@adamchainz
Copy link
Member

I'm not sure pytest could have fixed this upstream, because it's entirely code within pytest-django that is affected.

@blueyed
Copy link
Contributor

blueyed commented Jul 20, 2018

@jedie
Interesting.. would be nice if you could git-bisect it to e.g. a pytest commit, if you really think it is related to it.

@blueyed
Copy link
Contributor

blueyed commented Jul 20, 2018

(also make sure to not accidentally use #625, of course ;))

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

No branches or pull requests

3 participants