Title: unittest fails with "Start directory is not importable" when trying to run sourceless tests
Type: behavior Stage: patch review
Components: Library (Lib), Tests Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Pam.McANulty, Roman.Evstifeev, martin.panter, rbcollins, xdegaye
Priority: normal Keywords: patch

Created on 2016-04-26 13:42 by xdegaye, last changed 2016-07-21 13:31 by xdegaye.

File name Uploaded Description Edit
unittest.patch xdegaye, 2016-04-26 13:42 review
unittest_2.patch xdegaye, 2016-04-29 07:51 with a test case review
unittest_3.patch xdegaye, 2016-06-22 08:03 review
Messages (7)
msg264283 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-04-26 13:42
unittest fails to load tests when the tests are in a package that has an __init__.pyc file and no file.

Patch attached.
msg264338 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-04-27 01:53
Is this the same bug as Issue 26481? I.e. is it the unittest dicovery mode that is affected? Maybe close the other bug as a duplicate, since Xavier has provided a patch here.
msg264361 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-04-27 08:13
It seems to be the same bug.

Source-less distributions are useful on mobile devices where space is sparse.
msg264431 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2016-04-28 14:31
Could you please add a test case.
msg264472 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-04-29 07:51
Here is the patch with a test case.
I have checked that the new test case fails with 'Start directory is not importable"' when is not patched.
msg268918 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-06-20 18:36
Thanks for the review Pamela, indeed self.vfs is not defined.

The patched test_unittest runs without failure because the list_dir() nested function is never called. It is also never called in the un-patched version. Actually the un-patched test_discover_start_dir_is_package_calls_package_load_tests runs without failure when changing '' of vfs to 'foo' or whatever :(
msg269055 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-06-22 08:03
> the list_dir() nested function is never called
Verifying that load_tests is called is the purpose of this test. In this case should_recurse is false in _find_tests() and os.listdir() is not invoked by this method.

This new patch does not use vfs and list_dir and uses subtests to also check that does consider that a path refers to a package directory when it contains an '__init__.pyc' file and no '' file, and vice-versa.
Date User Action Args
2017-01-05 16:03:13xdegayeunlinkissue26865 dependencies
2016-07-21 13:31:21xdegayesetstage: test needed -> patch review
2016-06-22 08:03:09xdegayesetfiles: + unittest_3.patch

messages: + msg269055
2016-06-20 18:36:50xdegayesetmessages: + msg268918
2016-06-20 01:29:56Pam.McANultysetnosy: + Pam.McANulty
2016-05-07 12:20:25ppperrysettitle: unittest fails with "Start directory is not importable" -> unittest fails with "Start directory is not importable" when trying to run sourceless tests
2016-04-29 07:51:34xdegayesetfiles: + unittest_2.patch

messages: + msg264472
2016-04-28 14:31:57rbcollinssetnosy: + rbcollins

messages: + msg264431
stage: patch review -> test needed
2016-04-27 08:46:50martin.panterlinkissue26481 superseder
2016-04-27 08:13:14xdegayesetmessages: + msg264361
2016-04-27 01:53:35martin.pantersetnosy: + martin.panter
messages: + msg264338

components: + Tests
stage: patch review
2016-04-26 16:04:41zach.warelinkissue26865 dependencies
2016-04-26 16:00:38Roman.Evstifeevsetnosy: + Roman.Evstifeev
2016-04-26 13:42:17xdegayecreate