pytest-dev / nose2pytest

Scripts to convert Python Nose tests to PyTest
Other
38 stars 12 forks source link

Fully-qualified nose.tools.assert* calls are not converted #1

Closed QuLogic closed 7 years ago

QuLogic commented 8 years ago

Take the following as an example:

import nose.tools
from nose.tools import assert_true

def test_case1():
    assert_true(True is True)
    assert_true(False != True)

def test_case2():
    nose.tools.assert_true(True is True)
    nose.tools.assert_true(False != True)

When running nose2pytest on the above, the first test case in converted, but the fully-qualified calls (in test_case2) are not converted.

schollii commented 7 years ago

Just saw this, thanks for catching this... somehow I didn't get notified when issue created.

schollii commented 7 years ago

So I looked into this.

The problem is that supporting this would require some form of semantic analysis of the call to assert_true() to determine if it is the one from nose.tools. I am not aware of a robust way of doing this. For example, you could easily do "import nose.tools as nt" and then the script would have to look for statements of the form "nt.assert_true(...)". Plus the code might do e.g. "nt2 = nt; nt2.assert_true(...)" then the script would have to also look for "nt2.assert_true(...)".

The possiblities are endless so nose2pytest would have to actually resolve symbols to actual Python objects and test whether they are the right ones. I currently do not know how to do that, although code completion must have to do something similar so there must be a way.

In the meantime, I recommend using a search/replace, which should be really straightforward in this case. Nose2pytest could do it too but I would rather keep regexp matching out of it for now.

I have updated the Limitations section of the docs.

I'm closing this but feel free to re-open if there is something I've missed.