Suppress Warnings in pytest

Recently had this issue with pytest. Were running 100+ tests and some of it was throwing some warnings and the side effect of that warning was that all the warnings overwhelmed the system and pytest information was unavailable for us to debug anything.

  for arg in inspect.getargspec(self.__init__)[0]
c:\anaconda\envs\hfl\lib\site-packages\tables\atom.py:570: DeprecationWarning: i
nspect.getargspec() is deprecated, use inspect.signature() instead
  for arg in inspect.getargspec(self.__init__)[0]
c:\anaconda\envs\hfl\lib\site-packages\tables\atom.py:570: DeprecationWarning: i
nspect.getargspec() is deprecated, use inspect.signature() instead
  for arg in inspect.getargspec(self.__init__)[0]
c:\anaconda\envs\hfl\lib\site-packages\pandas\core\frame.py:6211: FutureWarning:
Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

  sort=sort)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
===== 18 failed, 117 passed, 1 skipped, 91875 warnings in 975.66 seconds ======


The above screengrab image shows the effect.

we know 18 tests failed out of 117, but scrolling up all we got was the warnings and no useful outputs.

Digging through pytest documentation, found this option that’s a lifesaver for this kind of situation.

Solution

pytest -v -p no:warnings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s