Changes between Initial Version and Version 1 of Ticket #30546


Ignore:
Timestamp:
Jun 5, 2019, 5:35:47 AM (5 years ago)
Author:
Sławek Ehlert
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30546 – Description

    initial v1  
    2828I'm not sure if this is by design, but the behaviour is certainly inconsistent on Py3 vs. Py2.
    2929
    30 I found this problem while trying to run our test suite on Python 3. Unittest framework does an obvious {{{if isinstance(obj, type) and issubclass(obj, case.TestCase):}}} check when collecting the test suite (see https://github.com/python/cpython/blob/v3.5.7/Lib/unittest/loader.py#L122), so when we have a module-level {{{SimpleLazyObject}}} (obviously it wraps a different function than the one I've given here, but also a failing) it gets unexpectedly evaluated and raises an exception, which prevents us from even gathering the tests on Python 3.
     30I found this problem while trying to run our test suite on Python 3. Unittest framework does an obvious {{{if isinstance(obj, type) and issubclass(obj, case.TestCase):}}} check when collecting the test suite (see https://github.com/python/cpython/blob/v3.5.7/Lib/unittest/loader.py#L122), so when we have a module-level {{{SimpleLazyObject}}} (obviously it wraps a different function than the one I've given here, but also a failing one) it gets unexpectedly evaluated and raises an exception, which prevents us from even gathering the tests on Python 3.
    3131
    3232I'm not really sure why this is happening. After some brief debugging, it looks like {{{isinstance}}} function on Python 3 is accessing the {{{__class__}}} attribute (which is wrapped with the {{{new_method_proxy}}} function - see https://github.com/django/django/blob/2.2.2/django/utils/functional.py#L348) causing evaluation of the underlying function, whereas on Python 2.7 {{{isinstance}}} doesn't seem to do that.
Back to Top