#32532: Provide friendlier error if a file path is passed as a test label when
running tests
-------------------------------------+-------------------------------------
Reporter: Chris | Owner: nobody
Jerdonek |
Type: | Status: new
Cleanup/optimization |
Component: Testing | Version: 3.1
framework | Keywords: DiscoverRunner,test
Severity: Normal | labels
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, if a user passes a file path as a test label to
`DiscoverRunner`, they will get a somewhat unfriendly error that looks
something like the following:
{{{
$ ./runtests.py test_runner/tests.py
Testing against Django installed in '.../django/django' with up to 8
processes
Traceback (most recent call last):
File "./runtests.py", line 593, in <module>
options.timing,
File "./runtests.py", line 325, in django_tests
failures = test_runner.run_tests(test_labels or get_installed())
File ".../django/django/test/runner.py", line 721, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File ".../django/django/test/runner.py", line 612, in build_suite
suite.addTests(tests)
File ".../unittest/suite.py", line 57, in addTests
for test in tests:
TypeError: 'NoneType' object is not iterable
}}}
This is because `DiscoverRunner.build_suite()` starts out with `tests =
None` in each iteration of the loop and doesn't have an `else` clause for
the file path case:
https://github.com/django/django/blob/6f5dbe9dbe45b23b3befe4f1cd2ea13b6049ab96/django/test/runner.py#L574-L600
I imagine this is a common error because the help string tells the user to
use "paths":
> "Optional path(s) to test modules; e.g. "i18n" or
"i18n.tests.TranslationTests.test_lazy_objects".
but without saying that file paths aren't allowed.
A more friendly error message could tell the user that they provided a
path to a file, but that only dotted module paths and directory paths are
supported.
--
Ticket URL: <https://code.djangoproject.com/ticket/32532>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.41f4ea436d06efed837f5122e8be98c3%40djangoproject.com.