unittest2pytest icon indicating copy to clipboard operation
unittest2pytest copied to clipboard

remove_class fix breaks code when there are decorators on methods

Open Code0x58 opened this issue 4 years ago • 0 comments

test patch
diff --git a/tests/fixtures/remove_class/assertEqual_in.py b/tests/fixtures/remove_class/assertEqual_in.py
index a84867b..2635814 100644
--- a/tests/fixtures/remove_class/assertEqual_in.py
+++ b/tests/fixtures/remove_class/assertEqual_in.py
@@ -7,3 +7,7 @@ class TestAssertNotEqual(TestCase):
 
     def test_you(self):
         self.assertNotEqual(abc, 'xxx')
+
+    @property
+    def test_me(self):
+        pass
diff --git a/tests/fixtures/remove_class/assertEqual_out.py b/tests/fixtures/remove_class/assertEqual_out.py
index 833d980..4da9970 100644
--- a/tests/fixtures/remove_class/assertEqual_out.py
+++ b/tests/fixtures/remove_class/assertEqual_out.py
@@ -5,3 +5,7 @@ def test_you(self):
 
 def test_you(self):
     self.assertNotEqual(abc, 'xxx')
+
+@property
+def test_me(self):
+    pass

Example test failure:

--- expected
+++ refactured result
@@ -6,6 +6,6 @@
 def test_you(self):
     self.assertNotEqual(abc, 'xxx')
 
-@property
-def test_me(self):
+    @property
+deftest_me(self):
     pass

This obliterates the code in the from the point of the decorator until the end of the file.

To avoid this, you can add --nofix=remove_class to your unittest2pytest invocation when running on files which would break.

Code0x58 avatar Nov 28 '20 17:11 Code0x58