Opened 15 years ago
Closed 13 years ago
#12658 closed Bug (fixed)
Import Errors in test files cause tests to be skipped if both the tests file and the models file have been split into folders
Reported by: | Matthew Schinckel | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.1 |
Severity: | Normal | Keywords: | |
Cc: | Malcolm Box | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
If you have an import error (or an error in a file that is trying to be imported) in a test file, then the tests from that file (possible even the whole app) are skipped.
This does not seem to present unless your tests have been split into seperate files inside a tests package/folder in your app.
This is discussed in the following thread http://groups.google.com/group/django-users/browse_thread/thread/70385d35ec43a6e3/
Note: this is not limited to recent trunk versions - I am running 1.1.1 and it manifests there too.
Attachments (2)
Change History (17)
comment:2 by , 15 years ago
Summary: | Import Errors in test files cause tests to be split. → Import Errors in test files cause tests to be skipped. |
---|
comment:3 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I think this is a duplicate of #12574. Please reopen if I've misunderstood the problem you are describing.
comment:4 by , 15 years ago
They sound similar but I don't think they are the same problem. #12574 reports a problem running Django's own tests, this one is reporting a problem running an application's tests. Unless the patch for #12574 is wrong (it changes only tests/runtests.py
and does not touch the code in test/simple.py
mentioned above) I don't see how this one can be a dupe of that one.
comment:5 by , 15 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
Yeah, since the patch in #12574 does not affect anything inside the django/ directory, only tests/, then it cannot fix my issue.
Which, as kmtracey stated, is running tests on my own apps, not on the django framework.
by , 15 years ago
Attachment: | 12658.diff added |
---|
Fix for syntax/import errors causing tests to be skipped.
comment:6 by , 15 years ago
Has patch: | set |
---|
comment:7 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Seems like this should have a test case to prove that it is indeed working.
comment:8 by , 14 years ago
I agree with Eric that this needs a test case. The test case doesn't need to be of the full test suite; just that the get_tests() method works. The model_package modeltest provides a set of test models that could be used.
I would also say that the "check that the module exists" logic should be replace with django.utils.module_loading.module_has_submodule(); this utility method was introduced in 1.2 to perform exactly the check that is being performed here, but in a more rigorous fashion.
comment:9 by , 14 years ago
Needs tests: | unset |
---|
I have created a testcase and updated the patch as requested to use module_has_submodule(). This patch was tested on 1.3 but should apply back to 1.2.
The error is also present in 1.1, but the module_has_submodule utility function isn't.
comment:10 by , 14 years ago
Cc: | added |
---|
comment:11 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:12 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
patch%2Btests.diff fails to apply cleanly on to trunk
comment:13 by , 13 years ago
Summary: | Import Errors in test files cause tests to be skipped. → Import Errors in test files cause tests to be skipped if both the tests file and the models file have been split into folders |
---|---|
UI/UX: | unset |
More information: it only occurs if both the tests file and the models file have been split into folders. This is due to the line in django.test.simple.get_tests that tries again to find the module:
mod = find_module(TEST_MODULE, [os.path.dirname(app_module.file)])
At this point, if the models file has been split, then app_module.file is the init.py file in the models directory, so os.path.dirname() of this gets the model directory, not the app directory. Thus, no tests module can be found (unless there was one in the models directory).
A really hacky solution is to capture the internal exception, and compare the arguments of the two exceptions. If they match, then it is the tests module that is missing. If it isn't then the problem is an import. I'm sure there is a much nicer solution, though. I'm not really even game to submit a patch for mine!