self passed to class methods in Python 3
See original GitHub issueThe test case provided by @JPFrancoia in issue #20 demonstrates a change in behaviour between Python 2 and 3.
In Python 2, the generated test case is:
import unittest
import upper
from upper import UpperObject
class UpperTest(unittest.TestCase):
def test_parse(self):
upperobject_instance = UpperObject()
self.assertEqual(
upperobject_instance.parse(to_up='hello world'),
'HELLO WORLD'
)
if __name__ == "__main__":
unittest.main()
While in Python 3, it is generated as:
from typing import Dict
from typing import List
import unittest
import upper
from upper import UpperObject
class UpperTest(unittest.TestCase):
def test_parse(self):
self.assertEqual(
UpperObject.parse(self=<upper.UpperObject object at 0x105b29240>,to_up='hello world'),
'HELLO WORLD'
)
if __name__ == "__main__":
unittest.main()
Notice that self has been passed into UpperObject.parse in the test case generated by Python 3. This should be investigated, as this unit test will not run.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Can I pass self as the first argument for class methods in python
I have seen some usage where they have defined the class as a class method but they still pass self as the first...
Read more >self in Python class - GeeksforGeeks
Self is the first argument to be passed in Constructor and Instance Method. Self must be provided as a First parameter to the...
Read more >How to use self in Python – explained with examples
This article helps you acquire knowledge on the self variable in Python and its internal working in Python.
Read more >Self in Python Class | What is the Use of Python Self? - Edureka
The self is used to represent the instance of the class. With this keyword, you can access the attributes and methods of the...
Read more >self in Python, Demystified - Programiz
The self keyword is used to represent an instance (object) of the given class. In this case, the two Cat objects cat1 and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
At the moment, you would have to post-process the output so that you instantiate the object first. You could try find & replacing “UpperObject.” with “UpperObject()”, and then “self=<[^>]+>” with nothing.
Another option would be moving the method out of a class. This may or may not be possible with your existing code base. Traditional functions shouldn’t be affected by this bug. See sample/gentests.py and sample/functions.py for an example on how you would set this up.
I’ll take a look at this this afternoon. Hopefully we’ll be able to get this sorted out for you quickly.
Ok, I think I know what the underlying issue is. Python 3 removed unbound methods, which our code was expecting.