写点什么

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

作者:虫无涯
  • 2023-03-17
    陕西
  • 本文字数:1966 字

    阅读完需:约 6 分钟

1 学习来源

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

2 依赖的环境

3 本文学习环境

  • Python:3.7.0


  • 操作系统:windows10,64位


  • Pycharm:2020.2

4 pytest 安装

  • 打开 cmd 命令行,直接输入:


pip install -U pytest
复制代码


  • 安装如下:


C:\Users\Administrator>pip install -U pytestLooking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement 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/sRequirement 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.2Successfully installed pytest-6.2.4
复制代码

5 查看 pytest 版本

  • 使用 pip show 命令


pip show pytest
复制代码


(venv) F:\pytest_study>pip show pytestName: pytestVersion: 6.2.4Summary: pytest: simple powerful testing with PythonHome-page: https://docs.pytest.org/en/latest/Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and othersAuthor-email:License: MITLocation: d:\python37\lib\site-packagesRequires: pluggy, importlib-metadata, attrs, iniconfig, toml, py, packaging, atomicwrites, coloramaRequired-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 ResultLogModuleNotFoundError: No module named '_pytest.resultlog'
复制代码


  • 是因为之前安装过pytest-rerunfailures是用例失败重跑,pytest-rerunfailures不能与pytest 6.1.0以上的版本一起使用,所以卸载pytest-rerunfailures后使用pytest-reportlog来代替即可;


# 卸载pytest-rerunfailurespip uninstall pytest-rerunfailures
# 安装pytest-reportlogpip install pytest-reportlog
复制代码


  • 再次查看 pytest 版本 OK 了


(venv) F:\pytest_study>pytest -Vpytest 6.2.4
复制代码


发布于: 刚刚阅读数: 5
用户头像

虫无涯

关注

专注测试领域各种技术研究、分享和交流~ 2019-12-11 加入

CSDN测试领域优质创作者 | CSDN博客专家 | 阿里云专家博主 | 华为云享专家 | 51CTO专家博主

评论

发布
暂无评论
pytest学习和使用1-pytest安装和版本查看_Python_虫无涯_InfoQ写作社区