Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
hekevintran opened this Issue · 15 comments
@hekevintran

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?

@jbalogh
Owner

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.

@hekevintran

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

@hekevintran

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?

@jbalogh
Owner

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.

@culebron

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?

@honza

@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

@leom

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

@wilbuick

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)
@erikrose
Owner

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).

@patrickcd

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.

@ke1g

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?

@mpurdon

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

@cmdelatorre

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.

@JREAM

NOSE_INCLUDE_EXE=1

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

@jwhitlock
Owner

This could be turned into a documentation hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.