pytest框架学习2-cmd运行pytest规则

系列文章目录

pytest框架学习1-环境准备及入门



前言

最近在学习python中的pytest框架,就想着写个博客记录下学习过程,收获。并加深下印象,参考:上海-悠悠-pytest
前面已经学习了pytest入门,现在做个笔记,记录下使用命令行运行pytest的各种规则


一、pytest常识

1. 用例设计原则

  • 文件名以test_.py文件和_test.py
  • 以test_开头的函数
  • 以Test开头的类
  • 以test_开头的方法
  • 所有的包package必须要有__init__.py文件

2. cmd中help帮助

查看pytest命令行参数,可以用pytest -h 或pytest --help查看

D:\Test\zx\基础\pytest基础>pytest -h
usage: pytest [options] [file_or_dir] [file_or_dir] [...]

positional arguments:
  file_or_dir

general:
  -k EXPRESSION         only run tests which match the given substring expression. An expression is
                        a python evaluatable expression where all names are substring-matched
                        against test names and their parent classes. Example: -k 'test_method or
                        test_other' matches all test functions and classes whose name contains
                        'test_method' or 'test_other', while -k 'not test_method' matches those that
                        don't contain 'test_method' in their names. -k 'not test_method and not
                        test_other' will eliminate the matches. Additionally keywords are matched to
                        classes and functions containing extra names in their
                        'extra_keyword_matches' set, as well as functions which have names assigned
                        directly to them. The matching is case-insensitive.
  -m MARKEXPR           only run tests matching given mark expression.
                        For example: -m 'mark1 and not mark2'.
  --markers             show markers (builtin, plugin and per-project ones).
  -x, --exitfirst       exit instantly on first error or failed test.
  --fixtures, --funcargs
                        show available fixtures, sorted by plugin appearance (fixtures with leading
                        '_' are only shown with &#
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值