jezdez / django-discover-runner

A Django test runner based on unittest2's test discovery.
http://pypi.python.org/pypi/django-discover-runner
Other
132 stars 13 forks source link

Failed import in test gives odd test error #14

Closed birdsarah closed 11 years ago

birdsarah commented 11 years ago

(First-up, many thanks for this excellent tool).

Here's my basic setup (all tests in one directory with sub directories for each apps tests:

- manage.py
- project/
-- appA/
--- stuff.py
-- tests/
--- appA/
---- test_for_stuff.py

I was writing a new test file, and I had an import error (I'd written from appA import X, instead of from appA.models import X)

When I ran the test by running:

 ./manage.py test project.appA.tests.test_for_stuff

I got the following error:

  File "/home/bird/Dev/aptivate/econsensus/django/econsensus/.ve/local/lib/python2.7/site-packages/django/test/simple.py", line 380, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/home/bird/Dev/aptivate/econsensus/django/econsensus/.ve/local/lib/python2.7/site-packages/discover_runner/runner.py", line 40, in build_suite
    suite = self.test_loader.loadTestsFromNames(test_labels)
  File "/usr/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_for_stuff'

I was a little confused by this because I thoguht it was trying to tell me my test_for_stuff file wasn't there.

I would have expected an ImportError.

jezdez commented 11 years ago

That's indeed odd, hmm. Wait, wouldn't you have to run ./manage.py test project.tests.appA.test_for_stuff? At least that's how I understand the directory structure you wrote above.

jezdez commented 11 years ago

Can you try with the recently released 1.0 version? That should fix the problem.

birdsarah commented 11 years ago

Hi,

I'm so sorry for the delay in responding, you're right about my dotted path being wrong above, but my bad on the typo, the bug seems to remain.

I've created an example repo so you can easily see the issue.

https://github.com/birdsarah/django-discover-runner-test

Tracking down the issue a bit, it seems to come from: https://github.com/jezdez/django-discover-runner/blob/master/discover_runner/runner.py#L73

Would love to help further if I can.

(I really hope I'm not doing something epically stupid and I apologize in advance if I am.)