当从没有pytest.ini文件的shell调用时,pytest忽略venv

2024-06-16 10:12:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

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

我如何才能在虚拟环境中运行pytest


我尝试过的

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

pytest --ignore=venv
pytest --ignore=./venv/
pytest --ignore="venv/*"
pytest --ignore="./venv/*"

source

并使用-k

pytest -k 'not venv'

source


我读过的内容

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

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

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


版本控制

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

Tags: the项目py警告venvpytestlibpackages