On 01/18/2010 10:21 PM, Olivier Guilyardi wrote:
> On 01/18/2010 10:04 PM, Ramiro Morales wrote:
>> On Mon, Jan 18, 2010 at 4:40 PM, Olivier Guilyardi <m...@xung.org> wrote:
>>> Hi,
>>>
>>> I'm trying to split tests.py into individual files into a tests/ subfolder, 
>>> but
>>> that doesn't work.
>>>
>>> I correctly import everything from within tests/__init__.py, as previously 
>>> said
>>> on this mailing list:
>>> http://groups.google.com/group/django-users/browse_frm/thread/10cfd65e398360d2/dae3a7226dccdc5f
>>>
>>> But that doesn't work. I tested on Django 1.0.2 and SVN r12255, same thing.
>>>
>>> Any clue?
>> What do you mean with "doesn't work" ?. Do you get a traceback? No
>> error but your
>> tests aren't being run?, ...
> 
> No error, the tests are not run. When splitting, it says:
> 
> Ran 0 tests in 0.000s
> 
> Instead of the following with tests.py:
> 
> Ran 14 tests in 1.875s
> 
>> Try with SVN r12254 because the test infrastructure was refactored in r12255
>> and it still has some small rough edges.
> 
> I reverted back to r12254, same problem.

Okay, I found the problem. In my tests I'm importing models, with something 
like:

from models import ...

That works when tests.py is located at the root of the app, that is: at the same
level as the models module.

But when splitting tests.py into individual files into tests/, models can't be
imported anymore. For it to work, I must use :

from my_app.models import ...

And now it works. The real problem here is that Django current behaviour is
silent failure, no error.

A little debugging led me in django.test.simple.get_tests() (at r12555 line 65):

    try:
        app_path = app_module.__name__.split('.')[:-1]
        test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {},
TEST_MODULE)
    except ImportError, e:
        # Couldn't import tests.py. Was it due to a missing file, or
        # due to an import error in a tests.py that actually exists?
        import os.path
        from imp import find_module
        try:
            mod = find_module(TEST_MODULE, 
[os.path.dirname(app_module.__file__)])
        except ImportError:
            # 'tests' module doesn't exist. Move on.
            test_module = None


Here the __import__ fails, not because the tests module is missing, but because
the tests module fails to import another module.

And then, the find_module() fallback fails too: my debugging shows that
os.path.dirname(app_module.__file__) points to /path/to/myapp/models and *not*
to /path/to/myapp as it should be.

This could be caused by the fact that my models are also split into models/,
thus dirname() returns a bogus value. But app_path above is correct, since it
doesn't rely on the fact the models module is a file...

Hum.. My head hurts ;)

-- 
  Olivier
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to