pytest-dev / pytest-dev/unittest2pytest

remove_class fix breaks code when there are decorators on methods

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
141
Forks
28
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tests/fixtures/remove_class/assertEqual_in.py and assertEqual_out.py fixtures, then reproduce the failure through the unittest2pytest invocation described in the issue. Inspect the remove_class transformation and verify that decorated methods retain the decorator, indentation, and function definition instead of corrupting the rest of the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.