Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest fails with "Start directory is not importable" when trying to run sourceless tests #71046

Open
xdegaye mannequin opened this issue Apr 26, 2016 · 7 comments
Open
Labels
stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented Apr 26, 2016

BPO 26859
Nosy @rbtcollins, @Fak3, @vadmium
Files
  • unittest.patch
  • unittest_2.patch: with a test case
  • unittest_3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2016-04-26.13:42:17.449>
    labels = ['tests', 'type-bug', 'library']
    title = 'unittest fails with "Start directory is not importable" when trying to run sourceless tests'
    updated_at = <Date 2019-12-10.08:16:01.494>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2019-12-10.08:16:01.494>
    actor = 'xdegaye'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2016-04-26.13:42:17.449>
    creator = 'xdegaye'
    dependencies = []
    files = ['42611', '42646', '43507']
    hgrepos = []
    issue_num = 26859
    keywords = ['patch']
    message_count = 7.0
    messages = ['264283', '264338', '264361', '264431', '264472', '268918', '269055']
    nosy_count = 4.0
    nosy_names = ['rbcollins', 'Roman.Evstifeev', 'martin.panter', 'Pam.McANulty']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26859'
    versions = ['Python 3.6']

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Apr 26, 2016

    unittest fails to load tests when the tests are in a package that has an __init__.pyc file and no __init__.py file.

    Patch attached.

    @xdegaye xdegaye mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 26, 2016
    @vadmium
    Copy link
    Member

    vadmium commented Apr 27, 2016

    Is this the same bug as bpo-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.

    @vadmium vadmium added the tests Tests in the Lib/test dir label Apr 27, 2016
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Apr 27, 2016

    It seems to be the same bug.

    Source-less distributions are useful on mobile devices where space is sparse.

    @rbtcollins
    Copy link
    Member

    Could you please add a test case.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Apr 29, 2016

    Here is the patch with a test case.
    I have checked that the new test case fails with 'Start directory is not importable"' when loader.py is not patched.

    @pppery pppery mannequin changed the title unittest fails with "Start directory is not importable" unittest fails with "Start directory is not importable" when trying to run sourceless tests May 7, 2016
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jun 20, 2016

    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 '__init__.py' of vfs to 'foo' or whatever :(

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jun 22, 2016

    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 TestLoader.discover() does consider that a path refers to a package directory when it contains an '__init__.pyc' file and no '__init__.py' file, and vice-versa.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants