Skip to content

ImportError is raised only when python -m unittest discover is given #76021

Description

@Hirokih2Horiuchi
BPO 31840
Nosy @pfmoore, @ronaldoussoren, @tjguk, @ned-deily, @zware, @serhiy-storchaka, @zooba
Files
  • test.py: runs or raises
  • 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 = <Date 2017-10-22.06:30:25.502>
    created_at = <Date 2017-10-22.06:06:57.230>
    labels = ['OS-mac', 'type-bug', 'library', 'invalid', 'tests', 'OS-windows']
    title = '`ImportError` is` raised` only when `python -m unittest discover` is given'
    updated_at = <Date 2017-10-22.06:30:25.489>
    user = 'https://bugs.python.org/Hirokih2Horiuchi'

    bugs.python.org fields:

    activity = <Date 2017-10-22.06:30:25.489>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-22.06:30:25.502>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'macOS', 'Tests', 'Windows']
    creation = <Date 2017-10-22.06:06:57.230>
    creator = 'Hiroki \xe2\x80\x9ch2\xe2\x80\x9d Horiuchi'
    dependencies = []
    files = ['47230']
    hgrepos = []
    issue_num = 31840
    keywords = []
    message_count = 2.0
    messages = ['304729', '304731']
    nosy_count = 8.0
    nosy_names = ['paul.moore', 'ronaldoussoren', 'tim.golden', 'ned.deily', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'Hiroki \xe2\x80\x9ch2\xe2\x80\x9d Horiuchi']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31840'
    versions = ['Python 2.7', 'Python 3.6']

    Activity

    1. Hirokih2Horiuchi commented on Oct 22, 2017

      Hirokih2Horiuchimannequin
      MannequinAuthor

      Create a package pkg. Put test.py there. Write none = None in pkg/__init__.py.
      In the directory containing pkg/, python [23] -m unittest pkg.test will terminate normally, but python [23] -m unittest discover pkg will raise ImportError. The phenomenon is the same in macOS Sierra, Debian 9.0, Windows 7. I do not think this is a very kind behavior.
      Thank you.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      testsTests in the Lib/test dir
      type-bugAn unexpected behavior, bug, or error
      on Oct 22, 2017
    3. serhiy-storchaka commented on Oct 22, 2017

      @serhiy-storchaka
      Member

      Run

      python -m unittest discover --start-directory pkg --top-level-directory .
      

      By default the top level directory is the same as the start directory (i.e. pkg).

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      OS-macOS-windowsstdlibStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions