有没有办法忽略py.test中的test/conftest.py?

san*_*nga 8 pytest

没有移动任何代码(我意识到我可以重构,但由于各种原因不方便),有没有办法调用py.test而忽略conftest.py?

我想:

py.test -p no:pytestconfig
Run Code Online (Sandbox Code Playgroud)

可能会奏效,但似乎没有.

小智 6

使用:

py.test --noconftest 
Run Code Online (Sandbox Code Playgroud)

根据py.test --help:

--noconftest不加载任何conftest.py文件。


Okk*_*ken 5

当然。使用pytest --trace-config并找到您不想加载的conftest.py。然后使用-p no:<path>/conftest.py告诉pytest不使用它。

例如,如果conftest.py文件在当前目录中,则可以正常工作(当然,如果使用bash):

pytest -p no:$(pwd)/conftest.py


小智 1

根据 py.test第 82 期

或许

py.test --confcutdir

可能有帮助。