django-nose icon indicating copy to clipboard operation
django-nose copied to clipboard

How do I tell django-nose where my tests are?

Open orientalperil opened this issue 13 years ago • 17 comments

I have my tests for a Django application in a tests directory:

my_project/apps/my_app/
├── __init__.py
├── tests
│   ├── __init__.py
│   ├── field_tests.py
│   └── storage_tests.py
├── urls.py
├── utils.py
└── views.py

The Django test runner requires that I put a suite() function in the __init__.py file of my application's tests directory. That function returns the test cases that will run when I do $ python manage.py test my_app

I installed django-nose. When I try to run the tests with django-nose, 0 tests are run: $ python manage.py test my_app

If I point directly at the test module, the tests are run: $ python manage.py test my_project.apps.my_app.tests.storage_tests

Why does django-nose's test runner not find my tests? What must I do?

orientalperil avatar May 19 '11 21:05 orientalperil

Do you have an __init__.py in my_project/apps? nose won't recurse further into directories if they don't look like Python packages.

jbalogh avatar May 19 '11 23:05 jbalogh

Yes I do. All directories in my project have an __init__.py file.

orientalperil avatar May 20 '11 00:05 orientalperil

Interestingly the following line works. $ python manage.py test my_project/apps/my_app/

I don't know why this works and the other command doesn't. I guess this is sufficient though.

There's nothing you can do by specifying the module path that you cannot do by specifying the directory path right?

orientalperil avatar May 20 '11 02:05 orientalperil

nose behaves a bit diferent than Django. It doesn't know about INSTALLED_APPS, it just knows about the python import path. If it's possible for you to do ./manage.py shell and import my_app then nose will be able to find it. If you have to import apps.my_app then you'll have to use that import path for nose.

jbalogh avatar May 20 '11 16:05 jbalogh

We work with hekevintran together, and this command still doesn't work:

$ python manage.py test my_project.apps.my_app

although there are __init__.py in all the folders. The my_project.apps.my_app has tests package in it, and storage_tests.py in it. When we run it with the command above, it's ignored. My question is, what does nose consider a test?

culebron avatar May 20 '11 18:05 culebron

@jbalogh is this still the case?

nose behaves a bit diferent than Django. It doesn't know about INSTALLED_APPS, it just knows about the python import path

honza avatar Oct 28 '11 13:10 honza

Has this been resolved? This is an issue for a coworker (but not me). The only way he can execute tests is via:

$> python manage.py test our_app.tests.test_models

or

$> python manage.py test our_app/tests/*

When we turn on -v, it doesn't find any other tests (in fact, it executes none). @culebron, did you guys ever find a solution for this problem?

Thanks

leom avatar Jan 30 '12 21:01 leom

For anyone else who was trying to figure out how to do this, this is what I came up with. You can create a new python file, import the NoseTestSuiteRunner and any other django apps you need. You can also subclass the NoseTestSuiteRunner and provide a default list of apps to test when you run bin/django test. You could also set the import path here if needed.

In the example below running bin/django test is equivalent to running bin/django test my_django_app

Hope this helps.

from django_nose import NoseTestSuiteRunner
from some.path import my_django_app

class MyNoseTestSuiteRunner(NoseTestSuiteRunner):
    def run_tests(self, test_labels, *args, **kwargs):
        """
        Django nose does not allow us to specify a default  app to test, so
        we can subclass to tell django nose to run the specified app if we
        do not specifically provide one on the command line.
        """
        if len(test_labels) == 0:
            test_labels = ('my_django_app',)
        return super(NoseTestSuiteRunner, self).run_tests(test_labels, *args,
                **kwargs)

wilbuick avatar May 06 '12 22:05 wilbuick

I would love if somebody could post a reduction of this—a teeny example project where django_nose doesn't find stuff. Sounds like something I'd like to fix (or at least make less surprising).

erikrose avatar May 19 '12 08:05 erikrose

I had a similar issue. The django nose runner was not finding tests unless given the full path to the tests in just one directory (valid python package). Running tests -v3, I noticed the following:

nose.selector: INFO: /home/path/to/tests.py is executable; skipped

When I changed the file permissions on those tests everything worked fine. Hope that helps someone.

patrickcd avatar Jun 15 '12 02:06 patrickcd

It is worth trying setting the environment variable NOSE_INCLUDE_EXE to a non-empty string.

While (at least currently) this is set by default on win32 and cli, and on *nix systems the tests.py file should get made without execute permissions, it is possible that if a site were created on a Windows box and copied to something else, you could wind up with the execute bits set (I've seen that - don't remember the details). Setting execute permissions on tests.py on a linux system certainly prevents the test from running, and using:

export NOSE_INCLUDE_EXE=1

makes it run again. If the OP is still having the problem, could he please try this?

ke1g avatar Sep 07 '12 16:09 ke1g

export NOSE_INCLUDE_EXE=1 worked for me. In addition, I wasn't aware that there was a level 3 (level 2 appeared to make no difference) to the verbosity so once I tried running the tests I was able to see several .py is executable; skipped results.

Thanks everyone

mpurdon avatar Oct 16 '12 19:10 mpurdon

export NOSE_INCLUDE_EXE=1

Yes! This is what I was looking for! I run Ubuntu but the disk partition I'm working on is shared with Windows (NTFS), so al files are 'executable' (so as to say).

Thank you very much for the help.

cmdelatorre avatar Nov 15 '13 11:11 cmdelatorre

NOSE_INCLUDE_EXE=1

This worked for me also by placing it in settings, thanks! I'm using Ubuntu.

JREAM avatar Mar 16 '15 05:03 JREAM

This could be turned into a documentation hint.

jwhitlock avatar Aug 05 '15 00:08 jwhitlock

I have been looking all over the internets on how to fix this! NOSE_INCLUDE_EXE=1 worked for me. This should be in the docs, please.

josellausas avatar Dec 19 '16 19:12 josellausas

Fun story, we use Docker across window and linux and mac, our test suite worked on Mac and Linux but not windows... in the same linux docker container... BLAH. @ke1g saved the day. Adding that fixes everything for the windows user.

jonathanstiansen avatar Jun 22 '18 16:06 jonathanstiansen