def METHOD_NAME(self, exception, expected, raised_exception, caplog):
    tmp = self.mkdtemp()
    path = os.path.join(tmp, 'xxx')
    self.write_file(path)
    dist_files = [('xxx', '2.6', path)]  # command, pyversion, filename
    self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
    pkg_dir, dist = self.create_dist(dist_files=dist_files)
    with mock.patch(
        'distutils.command.upload.urlopen',
        new=mock.Mock(side_effect=exception),
    ):
        with pytest.raises(raised_exception):
            cmd = upload(dist)
            cmd.ensure_finalized()
            cmd.run()
        results = caplog.messages
        assert expected in results[-1]
        caplog.clear()