7

I am trying to use pytest within my Mac's terminal. I do not have a pytest.ini set up, and do not wish to make one at this time.

When I run the command pytest alone, it prints warnings (DeprecationWarning) for multiple site packages within my virtual environment (named venv, located within my project's root directory).

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

I would like to ignore the venv/ directory when running pytest, so my warnings are relevant to my project only.

How can I not run pytest on my virtual environment?


What I Have Tried

I have tried multiple versions of the --ignore flag:

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

(source)

And using -k

pytest -k 'not venv'

(source)


What I Have Read

--disable-pytest-warnings: I still want other warnings to be displayed

--pythonwarnings ignore::DeprecationWarning seems too generic (what if one of my project files uses a deprecated module)

--pythonwarnings ignore::DeprecationWarning:some_package.*: is too manual (lots of my site packages generate warnings)


Versioning

  • macOS Mojave v10.14.3
  • Python 3.6.5
  • pytest==5.3.5
kaya3
  • 47,440
  • 4
  • 68
  • 97
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
  • 1
    That warning is not emitted by pytest. It's emitted from the `imp` module when `eventlet` imports it. Use one of the solutions you have already discovered. – jordanm Mar 10 '20 at 20:03
  • Have you tried `pytest --ignore=venv/`? What if you specify the folder that pytest has to look at (`pytest `)? Would that be an option? – dkreeft Jun 05 '20 at 13:30

0 Answers0