Skip to content

remove_class fix breaks code when there are decorators on methods #49

Description

@Code0x58
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.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions