berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

Test errors with Python 2.7 #90

Closed felixonmars closed 6 years ago

felixonmars commented 6 years ago

These are not present in 0.6, but present in 0.6.1 and latest 0.6.2 release:

======================================================================
ERROR: test_codegen_as_submodule (tests.test_misc.PublicAPITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6.2-py2/tests/test_misc.py", line 39, in test_codegen_as_submodule
    with self.assertWarns(DeprecationWarning) as cm:
AttributeError: 'PublicAPITestCase' object has no attribute 'assertWarns'

======================================================================
ERROR: test_codegen_from_root (tests.test_misc.PublicAPITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6.2-py2/tests/test_misc.py", line 28, in test_codegen_from_root
    with self.assertWarns(DeprecationWarning) as cm:
AttributeError: 'PublicAPITestCase' object has no attribute 'assertWarns'

----------------------------------------------------------------------
berkerpeksag commented 6 years ago

This is expected. You need to install the unittest2 module under Python 2:

https://github.com/berkerpeksag/astor/blob/68fbf65ed4eb7a9d5b0a3a380b57d3329012c2a4/tox.ini#L10

I could replace assertWarns usages with warnings.catch_warnings() in Python 2 but I think at this point it's not worth to spend too much time with Python 2 compatibility issues so I just decided to use unittest2 under Python 2.

felixonmars commented 6 years ago

I see, thanks for the info!