pytest-dev / unittest2pytest

helps rewriting Python `unittest` test-cases into `pytest` test-cases
GNU General Public License v3.0
128 stars 27 forks source link

Incorrect transformation due to line wrapping (syntax error) #3

Closed patrickdepinguin closed 8 years ago

patrickdepinguin commented 8 years ago

Consider following testcase:

import unittest

class TestClass(unittest.TestCase):
    def test_wrap(self):
        self.assertEqual(True, True, msg='some %s message' %
                'cool')

The transformation given by unittest2pytest 0.2 is:

--- ./test_example.py   (original)
+++ ./test_example.py   (refactored)
@@ -3,5 +3,5 @@

 class TestClass(unittest.TestCase):
      def test_wrap(self):
      -        self.assertEqual(True, True, msg='some %s message' %
      -                'cool')
      +        assert True == True, 'some %s message' %
      +                'cool'

Which results in:

――――――――――――――――――――――――― ERROR collecting test_example.py ―――――――――――――――――――――――――
../venv/lib/python2.7/site-packages/pytest-2.8.7-py2.7.egg/_pytest/python.py:610:
in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
    ../venv/lib/python2.7/site-packages/py-1.4.31-py2.7.egg/py/_path/local.py:650:
    in pyimport
        __import__(modname)
        E     File
        "/home/user/unittest2pytest-tmp/result/test_example.py",
        line 6
        E       assert True == True, 'some %s message' %
        E                                              ^
        E   SyntaxError: invalid syntax

Another example of line wrapping causing problems is this:

-        self.assertEqual(NotificationModel()
-                         .get_unread_cnt_for_user(self.u1), 0)
+        assert NotificationModel()
+                         .get_unread_cnt_for_user(self.u1) == 0