pytest学习和使用1-pytest安装和版本查看

举报
虫无涯 发表于 2023/01/16 09:15:58 2023/01/16
【摘要】 1 学习来源https://docs.pytest.org/en/latest/index.html 2 依赖的环境环境版本python>=3.6平台支持linux、windows 3 本文学习环境Python:3.7.0操作系统:windows10,64位Pycharm:2020.2 4 pytest安装打开cmd命令行,直接输入:pip install -U pytest安装如下:C:...

1 学习来源

https://docs.pytest.org/en/latest/index.html

2 依赖的环境

环境 版本
python >=3.6
平台 支持linux、windows

3 本文学习环境

  • Python:3.7.0
    在这里插入图片描述
  • 操作系统:windows10,64位
    在这里插入图片描述
  • Pycharm:2020.2

4 pytest安装

  • 打开cmd命令行,直接输入:
pip install -U pytest
  • 安装如下:
C:\Users\Administrator>pip install -U pytest
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pytest in d:\python37\lib\site-packages (5.3.2)
Collecting pytest
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a1/59/6821e900592fbe261f19d67e4def0cb27e52ef8ed16d9922c144961cc1ee/pytest-6.2.4-py3-none-any.whl (280 kB)
     |████████████████████████████████| 280 kB 1.6 MB/s
Requirement already satisfied: importlib-metadata>=0.12 in d:\python37\lib\site-packages (from pytest) (2.1.1)
Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in d:\python37\lib\site-packages (from pytest) (0.13.1)
Requirement already satisfied: colorama in d:\python37\lib\site-packages (from pytest) (0.4.4)
Requirement already satisfied: atomicwrites>=1.0 in d:\python37\lib\site-packages (from pytest) (1.4.0)
Requirement already satisfied: toml in d:\python37\lib\site-packages (from pytest) (0.10.2)
Requirement already satisfied: packaging in d:\python37\lib\site-packages (from pytest) (20.8)
Requirement already satisfied: attrs>=19.2.0 in d:\python37\lib\site-packages (from pytest) (20.3.0)
Requirement already satisfied: iniconfig in d:\python37\lib\site-packages (from pytest) (1.1.1)
Requirement already satisfied: py>=1.8.2 in d:\python37\lib\site-packages (from pytest) (1.10.0)
Requirement already satisfied: zipp>=0.5 in d:\python37\lib\site-packages (from importlib-metadata>=0.12->pytest) (1.2.0)
Requirement already satisfied: pyparsing>=2.0.2 in d:\python37\lib\site-packages (from packaging->pytest) (2.4.7)
Installing collected packages: pytest
  Attempting uninstall: pytest
    Found existing installation: pytest 5.3.2
    Uninstalling pytest-5.3.2:
      Successfully uninstalled pytest-5.3.2
Successfully installed pytest-6.2.4

5 查看pytest版本

  • 使用pip show命令
pip show pytest
(venv) F:\pytest_study>pip show pytest
Name: pytest
Version: 6.2.4
Summary: pytest: simple powerful testing with Python
Home-page: https://docs.pytest.org/en/latest/
Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
Author-email:
License: MIT
Location: d:\python37\lib\site-packages
Requires: pluggy, importlib-metadata, attrs, iniconfig, toml, py, packaging, atomicwrites, colorama
Required-by: pytest-xdist, pytest-rerunfailures, pytest-ordering, pytest-metadata, pytest-html, pytest-forked, pytest-cov, allure-pytest
  • 使用–version命令,如果报错提示如下:
    plugin = ep.load()
  File "d:\python37\lib\site-packages\importlib_metadata\__init__.py", line 105, in load
    module = import_module(match.group('module'))
  File "d:\python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "d:\python37\lib\site-packages\_pytest\assertion\rewrite.py", line 170, in exec_module
    exec(co, module.__dict__)
  File "d:\python37\lib\site-packages\pytest_rerunfailures.py", line 8, in <module>
    from _pytest.resultlog import ResultLog
ModuleNotFoundError: No module named '_pytest.resultlog'
  • 是因为之前安装过pytest-rerunfailures是用例失败重跑,pytest-rerunfailures不能与pytest 6.1.0以上的版本一起使用,所以卸载pytest-rerunfailures后使用pytest-reportlog来代替即可;
# 卸载pytest-rerunfailures
pip uninstall pytest-rerunfailures

# 安装pytest-reportlog
pip install pytest-reportlog
  • 再次查看pytest版本OK了
(venv) F:\pytest_study>pytest -V
pytest 6.2.4
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。