DamnWidget / anaconda

Anaconda turns your Sublime Text 3 in a full featured Python development IDE including autocompletion, code linting, IDE features, autopep8 formating, McCabe complexity checker Vagrant and Docker support for Sublime Text 3 using Jedi, PyFlakes, pep8, MyPy, PyLint, pep257 and McCabe that will never freeze your Sublime Text 3
http://damnwidget.github.io/anaconda/
GNU General Public License v3.0
2.22k stars 260 forks source link

Running nosetests fails #328

Open nfantone opened 9 years ago

nfantone commented 9 years ago

I'm really perplexed here. I'm struggling to understand what is Anaconda trying to do when running Current File Tests, with default settings, using nose.

I have a dead simple tests/test_sqlutils.py file, with one empty test that just does pass.

# -*- coding: utf-8 -*-
#
def test_func():
    pass

Running it form the command line is pretty straight forward and works as expected:

nosetests tests/test_sqlutils.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

However, executing things from within Anaconda ends in failure (Ctrl + Shift + p > Run Current File Tests).

ERROR: Failure: OSError (No such file /home/nfantone/dev/python/sql-tools/sql-tools.tests.test_sqlutils)
...
FAILED (errors=1)
[Finished in 0.2s with exit code 1]
[shell_cmd: nosetests sql-tools.tests.test_sqlutils]

What is going on here? What's sql-tools.tests.test_sqlutils? From the source code, I can see that this this line effectively replaces / for . in the test file path. Why isn't the shell command nosetests sql-tools/tests/test_sqlutils.py? That would actually work from the root of the project.

Do I need to restructure my tests? Anything to configure? This is rather obscure.

DamnWidget commented 9 years ago

Hi Take a look at the configuration examples. The tests runner is an addition to the package from one of our users, I am not that familiar with it myself as I always use the command line to run tests as I am really comfortable with the terminal.

nfantone commented 9 years ago

Hi, @DamnWidget. I did take a look at the examples. None of them seemed very useful, honestly. They show samples for running tests using Twisted, Django and unittest, which aren't my case (and, also, do not correspond with the default setup).

Any ideas? Could you, perhaps, point me to a sample project actually using Anaconda to run tests locally, that I could take a look at?

DamnWidget commented 9 years ago

What happens if you run the "Run full project tests suite"?

nfantone commented 9 years ago

At first, without adding anything new to my sublime-projectfile, running Run project tests ended correctly, but didn't find any tests to run.

Setting the "test_project_path" property to my project's root directory, made it work ok from within Anaconda.

.......
----------------------------------------------------------------------
Ran 7 tests in 0.051s

OK
[Finished in 0.2s]

I feel this should be reflected somewhere in the documentation. "test_project_path" is a mandatory configuration property if you intend to run this command.

Still no luck with Current File Tests, though.

ezk84 commented 9 years ago

The test runner is creating a module path from your project root to your current file and passing that to your test command, (hence the periods in the filename).

Next question is, is your test module importable from your project root?

nfantone commented 9 years ago

Isn't that what nose is for? Discovering tests and module imports?

If the functionality is running current file tests, why isn't Anaconda feeding to whatever command line I have configured in "test_command" the path of the currently displayed file?

ezk84 commented 9 years ago

The problem here is that this feature has been designed most likely by one user to cover their own use case for testing, which happens to be with module paths.

Maybe you'd like to contribute some code that returns the test file path instead with a way to switch back and forth between these two modes?

nfantone commented 9 years ago

Ok. I'll try to make a PR as soon as I'm able to. Could you, please, give some pointers as where to be looking at to add this changes?

Also, if I were to make the current settings work with my project (that is, running tests with module paths), how should I go about it?

My layout looks like this:

sql-tools/
    sql-tools/
        sqltools.py
        test/
            test_sqltools.py
ezk84 commented 9 years ago

The changes would have to go around this line in this file.

Looking at that function, the module path is built from the test_root to the current file. Looking up where test_root is set here it appears to be an undocumented config option named test_root that defaults to the window's current folder.

So why not try setting test_root in your project settings to ./sql_tools/ and seeing what happens. You can check which command the test runner tries to run by looking at the ST console Ctrl + `.

ezk84 commented 9 years ago

@nfantone Run into this same problem today and solved it by doing what I suggested above.

What I've found out:

So you will be able to make your scenario work by doing this:

Comment: This is a rather convoluted situation that deserves better documentation and perhaps even a rethinking of how to cover most use cases in a intuitive way.