Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
orientalperil opened this issue May 19, 2011 · 17 comments
Open

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

orientalperil opened this issue May 19, 2011 · 17 comments

Comments

@orientalperil
Copy link

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
Copy link
Contributor

jbalogh commented May 19, 2011

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.

@orientalperil
Copy link
Author

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

@orientalperil
Copy link
Author

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
Copy link
Contributor

jbalogh commented May 20, 2011

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
Copy link

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
Copy link

honza commented Oct 28, 2011

@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
Copy link

leom commented Jan 30, 2012

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
Copy link

wilbuick commented May 6, 2012

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
Copy link
Contributor

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
Copy link

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
Copy link

ke1g commented Sep 7, 2012

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
Copy link

mpurdon commented Oct 16, 2012

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
Copy link

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
Copy link

JREAM commented Mar 16, 2015

NOSE_INCLUDE_EXE=1

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

@jwhitlock
Copy link
Contributor

This could be turned into a documentation hint.

@josellausas
Copy link

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.

@jonathanstiansen
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests