Opened 7 years ago
Closed 4 years ago
#29127 closed Bug (fixed)
Running tagged tests hides any with syntax errors
Reported by: | Kryštof Řeháček | Owned by: | Chris Jerdonek |
---|---|---|---|
Component: | Testing framework | Version: | 2.0 |
Severity: | Normal | Keywords: | tests, tagged-tests, SyntaxError |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When I execute tests with syntax error without any argument then it shows SyntaxError: invalid syntax
as expected but when I execute tagged tests, then it shows that it ran 0 tests and it is OK and even error. So when tests with syntax executed with the --tag="some_tag" argument and they have syntax error then they complete with OK status.
Change History (9)
comment:1 by , 7 years ago
Summary: | manage.py executting tagged tests with syntax error does not show them → manage.py executing tagged tests with syntax error does not show them |
---|
comment:2 by , 7 years ago
Summary: | manage.py executing tagged tests with syntax error does not show them → Running tagged tests hides any with syntax errors |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 7 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
It looks like this behavior is ultimately due to Python's unittest TestLoader and not Django's test framework. In case of a SyntaxError when loading a test suite, it hits this line, which creates a _FailedTest object from it without raising an error. Then the django.test.runner.filter_tests_by_tags()
sees a _FailedTest object which won't have any tags and so it won't be run at all. Since tests are tagged using a decorator, tests in a file with a syntax error won't have any tags recognized for them anyway because the file cannot be evaluated. I don't think there's a reasonable fix for this and I'm not sure it should even be considered a bug, although the behavior is a bit misleading.
comment:5 by , 4 years ago
I think a possible solution for this would be to make it so that unittest.loader._FailedTest
objects always match when tags are provided. That would prevent the issue of tests falsely passing due to e.g. syntax errors.
comment:6 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:8 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The problem may be in
django.test.runner.filter_tests_by_tags()
.