更改标准(Python)测试发现
在测试收集过程中忽略路径
通过--ignore=path在cli上传递选项,可以轻松地在收集过程中忽略某些测试目录和模块。pytest允许多个 --ignore选项。例:
tests/
|-- example
| |-- test_example_01.py
| |-- test_example_02.py
| '-- test_example_03.py
|-- foobar
| |-- test_foobar_01.py
| |-- test_foobar_02.py
| '-- test_foobar_03.py
'-- hello
'-- world
|-- test_world_01.py
|-- test_world_02.py
'-- test_world_03.py
现在,如果你调用pytest使用,你会发现只收集测试模块,这不符合指定的模式:--ignore=tests/foobar/test_foobar_03.py --ignore=tests/hello/pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-5.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 5 items
tests/example/test_example_01.py . [ 20%]
tests/example/test_example_02.py . [ 40%]
tests/example/test_example_03.py . [ 60%]
tests/foobar/test_foobar_01.py . [ 80%]
tests/foobar/test_foobar_02.py . [100%]
========================= 5 passed in 0.02 seconds =========================
该--ignore-glob选项允许忽略基于Unix Shell样式通配符的测试文件路径。如果要排除测试模块与终端_01.