Pytest安装

本文详细介绍了Pytest的安装步骤,包括遇到的pip版本过旧和网络超时两个问题,提供了相应的解决方法,最后讲解了如何验证pytest是否安装成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pytest安装步骤

在Python目录下,cmd运行以下命令安装pytest

运行目录:
D:\Python\Python37>
执行命令:
pip install -U pytest

安装过程中遇到的问题:

1.pip安装pytest报错

报错内容:
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the ‘python -m pip install –upgrade pip’ command.

报错详情如下:

    20% |██████▌                         | 40kB 6.4kB/s eta 0:00:26Exception:
Traceback (most recent call last):
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 302, in _error_catcher
    yield
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 384, in read
    data = self._fp.read(amt)
  File "d:\python\python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 60, in read
    data = self.__fp.read(amt)
  File "d:\python\python37\lib\http\client.py", line 447, in read
    n = self.readinto(b)
  File "d:\python\python37\lib\http\client.py", line 491, in readinto
    n = self.fp.readinto(b)
  File "d:\python\python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "d:\python\python37\lib\ssl.py", line 1049, in recv_into
    return self.read(nbytes, buffer)
  File "d:\python\python37\lib\ssl.py", line 908, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\python37\lib\site-packages\pip\_internal\basecommand.py", line 228, in main
    status = self.run(options, args)
  File "d:\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 291, in run
    resolver.resolve(requirement_set)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 103, in resolve
    self._resolve_one(requirement_set, req)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 257, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 210, in _get_abstract_dist_for
    self.require_hashes
  File "d:\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 310, in prepare_linked_requirement
    progress_bar=self.progress_bar
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 837, in unpack_url
    progress_bar=progress_bar
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 674, in unpack_http_url
    progress_bar)
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 898, in _download_http_url
    _download_url(resp, link, content_file, hashes, progress_bar)
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 618, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "d:\python\python37\lib\site-packages\pip\_internal\utils\hashes.py", line 48, in check_against_chunks
    for chunk in chunks:
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 586, in written_chunks
    for chunk in chunks:
  File "d:\python\python37\lib\site-packages\pip\_internal\utils\ui.py", line 159, in iter
    for x in it:
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 575, in resp_read
    decode_content=False):
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 401, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "d:\python\python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 307, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

解决:

在命令行中运行以下命令,升级pip

python -m pip install --upgrade pip

运行成功后显示:

Successfully installed pip-18.0

2.运行pip install -U pytest时候报错

报错内容:
File “d:\python\python37\lib\site-packages\pip_vendor\urllib3\response.py”, line 336, in _error_catcher
raise ReadTimeoutError(self._pool, None, ‘Read timed out.’)
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=’files.pythonhosted.org’, port=443): Read timed out.

报错详情如下:

D:\Python\Python37>pip install -U pytest
Collecting pytest
  Downloading https://files.pythonhosted.org/packages/d2/86/7b9513da923b94e48c2cf013ae4eae8184a36ebeb7fe27d386bc3db4f56f/pytest-3.7.1-py2.py3-none-any.whl (202kB)
    100% |████████████████████████████████| 204kB 47kB/s
Collecting py>=1.5.0 (from pytest)
  Downloading https://files.pythonhosted.org/packages/f3/bd/83369ff2dee18f22f27d16b78dd651e8939825af5f8b0b83c38729069962/py-1.5.4-py2.py3-none-any.whl (83kB)
    100% |████████████████████████████████| 92kB 49kB/s
Collecting pluggy>=0.7 (from pytest)
  Downloading https://files.pythonhosted.org/packages/f5/f1/5a93c118663896d83f7bcbfb7f657ce1d0c0d617e6b4a443a53abcc658ca/pluggy-0.7.1-py2.py3-none-any.whl
Collecting six>=1.10.0 (from pytest)
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting attrs>=17.4.0 (from pytest)
  Downloading https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl
Collecting more-itertools>=4.0.0 (from pytest)
  Downloading https://files.pythonhosted.org/packages/79/b1/eace304ef66bd7d3d8b2f78cc374b73ca03bc53664d78151e9df3b3996cc/more_itertools-4.3.0-py3-none-any.whl (48kB)
    21% |███████                         | 10kB 10.2MB/s eta 0:00:01Exception:
Traceback (most recent call last):
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 331, in _error_catcher
    yield
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 413, in read
    data = self._fp.read(amt)
  File "d:\python\python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "d:\python\python37\lib\http\client.py", line 447, in read
    n = self.readinto(b)
  File "d:\python\python37\lib\http\client.py", line 491, in readinto
    n = self.fp.readinto(b)
  File "d:\python\python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "d:\python\python37\lib\ssl.py", line 1049, in recv_into
    return self.read(nbytes, buffer)
  File "d:\python\python37\lib\ssl.py", line 908, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\python37\lib\site-packages\pip\_internal\basecommand.py", line 141, in main
    status = self.run(options, args)
  File "d:\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 299, in run
    resolver.resolve(requirement_set)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
    self._resolve_one(requirement_set, req)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "d:\python\python37\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
    self.require_hashes
  File "d:\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 283, in prepare_linked_requirement
    progress_bar=self.progress_bar
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 836, in unpack_url
    progress_bar=progress_bar
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 673, in unpack_http_url
    progress_bar)
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 897, in _download_http_url
    _download_url(resp, link, content_file, hashes, progress_bar)
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 617, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "d:\python\python37\lib\site-packages\pip\_internal\utils\hashes.py", line 48, in check_against_chunks
    for chunk in chunks:
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 585, in written_chunks
    for chunk in chunks:
  File "d:\python\python37\lib\site-packages\pip\_internal\utils\ui.py", line 159, in iter
    for x in it:
  File "d:\python\python37\lib\site-packages\pip\_internal\download.py", line 574, in resp_read
    decode_content=False):
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 465, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "d:\python\python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 336, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

解决:

切换运行目录,重新执行命令即可。

运行目录:
D:\Python\Python37\Scripts>
执行命令:
pip install -U pytest

验证是否安装成功

运行命令查看
1.

pytest

如下:
这里写图片描述

2.查看版本

pytest --version

如下:
这里写图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值