How to tell py.test to skip certain directories?

2020-05-29 12:39发布

I tried to use the norecursedirs option inside setup.cfg to tell py.test not to collect tests from certain directories but it seems it does ignore it.

[tool:pytest]
norecursedirs=lib/third

When I run py.test I do see how it does get tests from inside lib/third!

7条回答
该账号已被封号
2楼-- · 2020-05-29 13:07

You can use

py.test -k 'not third'

that excludes all 'third' directory contents.

查看更多
做自己的国王
3楼-- · 2020-05-29 13:09

I solved the mystery: If a pytest section is found in one of the possible config files (pytest.ini, tox.ini and setup.cfg), pytest will not look for any others so be sure you define the py.test options in a single file.

I would suggest using setup.cfg.

查看更多
女痞
4楼-- · 2020-05-29 13:12

py.test --ignore=somedir worked for me

查看更多
聊天终结者
5楼-- · 2020-05-29 13:16

If you have several directories with different parents you can specify different --ignore parameters:

py.test --ignore=somedir --ignore=otherdir --ignore=etcdir

  • new option: --ignore will prevent specified path from collection.
    Can be specified multiple times.
查看更多
狗以群分
6楼-- · 2020-05-29 13:16

If you are using setup.cfg, you have to use [tool:pytest] as per http://doc.pytest.org/en/latest/example/pythoncollection.html

# content of pytest.ini
# can also be defined in tox.ini or setup.cfg file, although the section
# name in setup.cfg files should be "tool:pytest"

查看更多
SAY GOODBYE
7楼-- · 2020-05-29 13:20

norecursedirs should work. Check whether you have a pytest.ini or other setup.cfg files. How are you invoking py.test?

查看更多
登录 后发表回答