系列文章目录
文章目录
前言
最近在学习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 &#