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

bpo-15010, unittest: _top_level_dir is incorrectly persisted #15242

Open

Conversation

@ZackerySpytz
Copy link
Contributor

commented Aug 13, 2019

bpo-15010, unittest: _top_level_dir is incorrectly persisted
Co-Authored-By: Igor Sobreira <igor@igorsobreira.com>
sys.path[:] = original_sys_path
self.addCleanup(restore)

os.path.isfile = lambda path: True

This comment has been minimized.

Copy link
@tirkarthi

tirkarthi Aug 13, 2019

Contributor

Is unittest.mock.patch a better option here instead of addCleanup?

def test_discover_should_not_persist_top_level_dir_between_calls(self):
    with unittest.mock.patch('os.path.isfile', return_value=True):
        with unittest.mock.patch('os.path.isdir', return_value=True):
            loader = unittest.TestLoader()
            loader.suiteClass = str
            dir = '/foo/bar'
            top_level_dir = '/foo'

            loader.discover(dir, top_level_dir=top_level_dir)
            self.assertEqual(loader._top_level_dir, None)

            loader._top_level_dir = dir2 = '/previous/dir'
            loader.discover(dir, top_level_dir=top_level_dir)
            self.assertEqual(loader._top_level_dir, dir2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.