AbdealiLoKo / pytest-attrib

A pytest plugin that mimics the working of nose-attrib
MIT License
3 stars 1 forks source link

Subclasses in python3 #3

Closed AbdealiLoKo closed 8 years ago

AbdealiLoKo commented 8 years ago

Not all tests of Subclasses are being used correctly. Here is the related build error: https://travis-ci.org/AbdealiJK/pytest-attrib/jobs/131589397

Here, if I have:

import unittest
class OneTest(unittest.TestCase):
    def test_one(self): pass
OneTest.xyz = "xyz"

class TwoTest(OneTest):  # Inherited
    def test_two(self): pass
    xyz2 = "xyz2"

And run -a xyz, the following functions are "found" by the pytest-attrib hook:

<function OneTest.test_one at 0xb66c702c>
<function OneTest.test_one at 0xb66c702c>
<function TwoTest.test_two at 0xb66c7194>

The same in python2 is:

<unbound method OneTest.test_one>
<unbound method TwoTest.test_one>
<unbound method TwoTest.test_two>

So, it can be seen that in Python2 it clearly has TwoTest.test_one for the test_one inherited into TwoTest. In python3 because all class methods are considered as functions, this distinctions isnt there aymore :|

AbdealiLoKo commented 8 years ago

According to the last function at http://nose.readthedocs.io/en/latest/plugins/attrib.html nose-attrib just ignores this. I uses im_class if found, else ignores the class completely (In py3 im_class doesnt exist). Which is not correct ... Atleast we try to do something better using the magic at https://github.com/AbdealiJK/pytest-attrib/commit/9c762ae89803df2cd8e9b58028b69b75b1c828c5#diff-d4305ea4d8fc4a0a5841dab8ef2f921cR51

AbdealiLoKo commented 8 years ago

Making a test and marking as xfail for now. no tool seems to handle this python3 case ... (As far as I know). If we find a better method to do this, I'll implement it. But until then, some of the tests will not be detected correctly.

jayvdb commented 8 years ago

:+1:

AbdealiLoKo commented 8 years ago

Also ran it on travis with pywikibot-core:

Tested the logs using http://pastebin.com/FnMQThYK and found that pytest-attrib only selects more tests than nose-attrib. All of those should be selected, so there seems to be some issue with nose-attr because it doesnt select it.

jayvdb commented 8 years ago

:sparkles: