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

_top_level_dir state leaks on defaultTestLoader #67000

Closed
rbtcollins opened this issue Nov 7, 2014 · 2 comments
Closed

_top_level_dir state leaks on defaultTestLoader #67000

rbtcollins opened this issue Nov 7, 2014 · 2 comments
Labels
stdlib Python modules in the Lib dir

Comments

@rbtcollins
Copy link
Member

BPO 22811
Nosy @rbtcollins, @ZackerySpytz
Superseder
  • bpo-15010: unittest: _top_level_dir is incorrectly persisted between calls to different load_test methods
  • 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 2021-11-27.11:55:01.382>
    created_at = <Date 2014-11-07.06:05:12.228>
    labels = ['library']
    title = '_top_level_dir state leaks on defaultTestLoader'
    updated_at = <Date 2021-11-27.11:55:01.381>
    user = 'https://github.com/rbtcollins'

    bugs.python.org fields:

    activity = <Date 2021-11-27.11:55:01.381>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-11-27.11:55:01.382>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2014-11-07.06:05:12.228>
    creator = 'rbcollins'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 22811
    keywords = []
    message_count = 2.0
    messages = ['230770', '349512']
    nosy_count = 2.0
    nosy_names = ['rbcollins', 'ZackerySpytz']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '15010'
    type = None
    url = 'https://bugs.python.org/issue22811'
    versions = ['Python 3.5']

    @rbtcollins
    Copy link
    Member Author

    TestProgram uses defaultTestLoader to load tests. Calling discover() on a TestLoader sets _top_level_dir. Calling discover with no top_level_dir implictly sets _top_level_dir but only the first time: the second time it is called with a different start_dir the prior one is used.

    This leads to errors like:
    ======================================================================
    ERROR: test_run_list_failed_import (testtools.tests.test_run.TestRun)
    testtools.tests.test_run.TestRun.test_run_list_failed_import
    ----------------------------------------------------------------------

    _StringException: Traceback (most recent call last):
      File "/home/robertc/personal/testtools/testtools/tests/test_run.py", line 175, in test_run_list_failed_import
        run.main, ['prog', 'discover', '-l', broken.package.base, '*.py'], out)
      File "/home/robertc/personal/testtools/testtools/testcase.py", line 420, in assertRaises
        self.assertThat(our_callable, matcher)
      File "/home/robertc/personal/testtools/testtools/testcase.py", line 431, in assertThat
        mismatch_error = self._matchHelper(matchee, matcher, message, verbose)
      File "/home/robertc/personal/testtools/testtools/testcase.py", line 481, in _matchHelper
        mismatch = matcher.match(matchee)
      File "/home/robertc/personal/testtools/testtools/matchers/_exception.py", line 108, in match
        mismatch = self.exception_matcher.match(exc_info)
      File "/home/robertc/personal/testtools/testtools/matchers/_higherorder.py", line 62, in match
        mismatch = matcher.match(matchee)
      File "/home/robertc/personal/testtools/testtools/testcase.py", line 412, in match
        reraise(*matchee)
      File "/home/robertc/personal/testtools/testtools/matchers/_exception.py", line 101, in match
        result = matchee()
      File "/home/robertc/personal/testtools/testtools/testcase.py", line 965, in __call__
        return self._callable_object(*self._args, **self._kwargs)
      File "/home/robertc/personal/testtools/testtools/run.py", line 413, in main
        stdout=stdout)
      File "/home/robertc/personal/testtools/testtools/run.py", line 208, in __init__
        self.parseArgs(argv)
      File "/home/robertc/personal/testtools/testtools/run.py", line 252, in parseArgs
        self._do_discovery(argv[2:])
      File "/home/robertc/personal/testtools/testtools/run.py", line 368, in _do_discovery
        loaded = loader.discover(self.start, self.pattern, self.top)
      File "/home/robertc/.virtualenvs/testtools-2.7/local/lib/python2.7/site-packages/unittest2/loader.py", line 353, in discover
        raise ImportError('Start directory is not importable: %r' % start_dir)
    ImportError: Start directory is not importable: '/tmp/tmpac4uwI'

    When a test tries to test the behaviour of TestProgram (or a subclass thereof).

    The fix is straight forward: at the end of discover restore the value of _top_level_dir that it had at entry.

    @rbtcollins rbtcollins added the stdlib Python modules in the Lib dir label Nov 7, 2014
    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Aug 13, 2019

    It seems that this issue is a duplicate of bpo-15010.

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants