pytest 在没有 pytest.ini 文件的情况下从 shell 调用时忽略 venv

Int*_*rer 7 python pytest site-packages

pytest我正在尝试在我的 Mac 终端中使用。我没有pytest.ini设置,现在也不想进行设置。

当我单独运行该命令时pytest,它会DeprecationWarning为我的虚拟环境(名为venv,位于我的项目根目录中)中的多个站点包打印警告 ( )。

venv/lib/python3.6/site-packages/eventlet/patcher.py:1
  /path/to/venv/lib/python3.6/site-packages/eventlet/patcher.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp
Run Code Online (Sandbox Code Playgroud)

我想venv/在运行时忽略该目录pytest,因此我的警告仅与我的项目相关。

我如何无法pytest我的虚拟环境中运行?


我尝试过的

我尝试过该--ignore标志的多个版本:

venv/lib/python3.6/site-packages/eventlet/patcher.py:1
  /path/to/venv/lib/python3.6/site-packages/eventlet/patcher.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp
Run Code Online (Sandbox Code Playgroud)

来源

并使用-k

pytest --ignore=venv
pytest --ignore=./venv/
pytest --ignore="venv/*"
pytest --ignore="./venv/*"
Run Code Online (Sandbox Code Playgroud)

来源


我读过的内容

--disable-pytest-warnings: 我仍然希望显示其他警告

--pythonwarnings ignore::DeprecationWarning似乎太通用了(如果我的项目文件之一使用了已弃用的模块怎么办)

--pythonwarnings ignore::DeprecationWarning:some_package.*:过于手动(我的很多站点包都会生成警告)


版本控制

  • macOS Mojave v10.14.3
  • Python 3.6.5
  • pytest==5.3.5