Opened 18 years ago

Closed 17 years ago

#3731 closed (worksforme)

Missing exception output with `manage.py test`

Reported by: Benjamin Schwarze Owned by: ttarabula
Component: Testing framework Version: dev
Severity: Keywords: sprintsept14
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried to set up a splitted test environment today.

I created a tests directory within my application directory and added an __init__.py file.
This looks like that:

mysite
  - myapp
    - tests
      - __init__.py

Within the __init__.py file I imported my test cases from other modules.

After that I executed the test suite via:

bschwarze@devbox:~/mysite$ ./manage.py test
Creating test database...
Creating table django_admin_log
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table myapp_car
Installing index for admin.LogEntry model
Installing index for auth.Message model
Installing index for auth.Permission model
Installing index for myapp.Car model
Loading 'initial_data' fixtures...
No fixtures found.

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database...

But it reported Run 0 tests ..., although I was sure I added my tests correctly.
After asking for help in Django IRC, I tried to import my tests module in Django shell.

This gave me an import error. After fixing that everything worked fine.

I think manage.py test should output such import errors, too.

Change History (6)

comment:1 by Chris Beaven, 18 years ago

Summary: Missing exception output with splitted tests.pyMissing exception output with `manage.py test`
Triage Stage: UnreviewedDesign decision needed

comment:2 by Russell Keith-Magee, 17 years ago

Triage Stage: Design decision neededAccepted

Silent failure is never a good thing.

comment:3 by ttarabula, 17 years ago

Owner: changed from nobody to ttarabula
Status: newassigned

comment:4 by ttarabula, 17 years ago

Keywords: sprintsept14 added

comment:5 by ttarabula, 17 years ago

Triage Stage: AcceptedUnreviewed

Can't replicate this bug. It appears to have been fixed at some point.

In django.test.simple, the inner try/except seems to deal with this case:

def get_tests(app_module):
    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
        else:
            # The module exists, so there must be an import error in the 
            # test module itself. We don't need the module; so if the
            # module was a single file module (i.e., tests.py), close the file
            # handle returned by find_module. Otherwise, the test module
            # is a directory, and there is nothing to close.
            if mod[0]:
                mod[0].close()
            raise
    return test_module

comment:6 by ttarabula, 17 years ago

Resolution: worksforme
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top