Skip to content

Tests failing on Python 2 #656

Closed

Description

@lwfitzgerald

Tests are failing on the 3.7.4 tag on Python 2

# python --version
Python 2.7.13 :: Continuum Analytics, Inc.
# python test_typing.py
.................................................................................................................................................................E.......E..E..........................................................
======================================================================
ERROR: test_protocol_instance_works (__main__.ProtocolTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_typing.py", line 1057, in test_protocol_instance_works
    self.assertNotIsInstance('no', typing.SupportsAbs)
  File "/usr/lib/python2.7/unittest/case.py", line 971, in assertNotIsInstance
    if isinstance(obj, cls):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1824, in __instancecheck__
    issubclass(instance.__class__, self)):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1407, in __subclasscheck__
    return super(GenericMeta, self).__subclasscheck__(cls)
  File "/usr/lib/python2.7/abc.py", line 180, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1401, in __subclasscheck__
    raise TypeError("Parameterized generics cannot be used with class "
TypeError: Parameterized generics cannot be used with class or instance checks

======================================================================
ERROR: test_reversible (__main__.ProtocolTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_typing.py", line 1049, in test_reversible
    self.assertNotIsSubclass(int, typing.Reversible)
  File "test_typing.py", line 42, in assertNotIsSubclass
    if issubclass(cls, class_or_tuple):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1407, in __subclasscheck__
    return super(GenericMeta, self).__subclasscheck__(cls)
  File "/usr/lib/python2.7/abc.py", line 180, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1401, in __subclasscheck__
    raise TypeError("Parameterized generics cannot be used with class "
TypeError: Parameterized generics cannot be used with class or instance checks

======================================================================
ERROR: test_supports_abs (__main__.ProtocolTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_typing.py", line 1045, in test_supports_abs
    self.assertNotIsSubclass(str, typing.SupportsAbs)
  File "test_typing.py", line 42, in assertNotIsSubclass
    if issubclass(cls, class_or_tuple):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1407, in __subclasscheck__
    return super(GenericMeta, self).__subclasscheck__(cls)
  File "/usr/lib/python2.7/abc.py", line 180, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1847, in __subclasscheck__
    return super(_ProtocolMeta, self).__subclasscheck__(cls)
  File "/home/lwfitzgerald/typing/python2/typing.py", line 1401, in __subclasscheck__
    raise TypeError("Parameterized generics cannot be used with class "
TypeError: Parameterized generics cannot be used with class or instance checks

----------------------------------------------------------------------
Ran 231 tests in 0.339s

FAILED (errors=3)

Activity

  1. ilevkivskyi commented on Jul 5, 2019

    @ilevkivskyi
    Member

    Hm, interesting. The tests pass if I use pytest, but do indeed fail if I just use python test_typing.py.
    Let me try manually the things that should be tested by tests manually.

  2. ilevkivskyi commented on Jul 5, 2019

    @ilevkivskyi
    Member

    I manually tried all the functionality tested by these tests and it works. This may be because we use a pretty dirty hack sys._getframe() and unittest does something wrong with it.

    Is this urgent, or you can use pytest instead (or just skip these tests)?

  3. lwfitzgerald commented on Jul 8, 2019

    @lwfitzgerald
    Author

    I can definitely switch to pytest in the meantime.

    However, there is something weirder than just the use of sys._getframe going on. Clearing the .pycs seems to make the tests pass:

    First run after .pycs deleted:

    λ LONMVMHUY MAC python2 → python2 -m unittest test_typing                                                                                                   λ git tags/3.7.4|✚1 →
    .......................................................................................................................................................................................................................................
    ----------------------------------------------------------------------
    Ran 231 tests in 0.107s
    
    OK
    

    Second run after pycs have been re-created:

    λ LONMVMHUY MAC python2 → python2 -m unittest test_typing                                                                                                   λ git tags/3.7.4|✚1 →
    .................................................................................................................................................................E.......E..E..........................................................
    ======================================================================
    ERROR: test_protocol_instance_works (test_typing.ProtocolTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "test_typing.py", line 1057, in test_protocol_instance_works
        self.assertNotIsInstance('no', typing.SupportsAbs)
      File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 972, in assertNotIsInstance
        if isinstance(obj, cls):
      File "typing.py", line 1824, in __instancecheck__
        issubclass(instance.__class__, self)):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1407, in __subclasscheck__
        return super(GenericMeta, self).__subclasscheck__(cls)
      File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 180, in __subclasscheck__
        if issubclass(subclass, scls):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1401, in __subclasscheck__
        raise TypeError("Parameterized generics cannot be used with class "
    TypeError: Parameterized generics cannot be used with class or instance checks
    
    ======================================================================
    ERROR: test_reversible (test_typing.ProtocolTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "test_typing.py", line 1049, in test_reversible
        self.assertNotIsSubclass(int, typing.Reversible)
      File "test_typing.py", line 42, in assertNotIsSubclass
        if issubclass(cls, class_or_tuple):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1407, in __subclasscheck__
        return super(GenericMeta, self).__subclasscheck__(cls)
      File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 180, in __subclasscheck__
        if issubclass(subclass, scls):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1401, in __subclasscheck__
        raise TypeError("Parameterized generics cannot be used with class "
    TypeError: Parameterized generics cannot be used with class or instance checks
    
    ======================================================================
    ERROR: test_supports_abs (test_typing.ProtocolTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "test_typing.py", line 1045, in test_supports_abs
        self.assertNotIsSubclass(str, typing.SupportsAbs)
      File "test_typing.py", line 42, in assertNotIsSubclass
        if issubclass(cls, class_or_tuple):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1407, in __subclasscheck__
        return super(GenericMeta, self).__subclasscheck__(cls)
      File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 180, in __subclasscheck__
        if issubclass(subclass, scls):
      File "typing.py", line 1847, in __subclasscheck__
        return super(_ProtocolMeta, self).__subclasscheck__(cls)
      File "typing.py", line 1401, in __subclasscheck__
        raise TypeError("Parameterized generics cannot be used with class "
    TypeError: Parameterized generics cannot be used with class or instance checks
    
    ----------------------------------------------------------------------
    Ran 231 tests in 0.107s
    
    FAILED (errors=3)
    

    Invoking with PYTHONDONTWRITEBYTECODE=1 set makes the tests pass every time:

    λ LONMVMHUY MAC python2 → PYTHONDONTWRITEBYTECODE=1 python2 -m unittest test_typing                                                                         λ git tags/3.7.4|✚1 →
    .......................................................................................................................................................................................................................................
    ----------------------------------------------------------------------
    Ran 231 tests in 0.106s
    
    OK
    
  4. added 3 commits that reference this issue on Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions