New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings not captured during test collection #3251

Closed
jaraco opened this Issue Feb 22, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@jaraco
Contributor

jaraco commented Feb 22, 2018

The warnings docs clearly state that it captures warnings during test execution, but that means any warnings issued during test collection will not be captured and will silently pass. Consider this slight tweak to the canonical example:

$ cat test_show_warnings.py 
import warnings


warnings.warn("foo", UserWarning)


def test_one():
    assert True
$ .tox/python/bin/pytest test_show_warnings.py -s
====================================== test session starts =======================================
platform darwin -- Python 3.7.0b1, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /Users/jaraco/warnings, inifile:
collecting 0 items                                                                               /Users/jaraco/warnings/test_show_warnings.py:4: UserWarning: foo
  warnings.warn("foo", UserWarning)
collected 1 item                                                                                 

test_show_warnings.py .

==================================== 1 passed in 0.00 seconds ====================================
$ .tox/python/bin/pytest test_show_warnings.py   
====================================== test session starts =======================================
platform darwin -- Python 3.7.0b1, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /Users/jaraco/warnings, inifile:
collected 1 item                                                                                 

test_show_warnings.py .                                                                    [100%]

==================================== 1 passed in 0.00 seconds ====================================

Would it be possible for the warnings feature to also be enabled during test collection, such that warnings like these could also be captured and reported and tweaked by the pytest config?

@nicoddemus

This comment has been minimized.

Show comment
Hide comment
@nicoddemus

nicoddemus Feb 22, 2018

Member

Hi @jaraco, thanks for writing down this issue, this was a known limitation that was supposed to be registered in an issue already but it seems it got forgotten.

It should be perfectly possible to capture and display warnings during collection, so hopefully this is something that will be tackled in the internal warnings refactoring for 3.5.

Member

nicoddemus commented Feb 22, 2018

Hi @jaraco, thanks for writing down this issue, this was a known limitation that was supposed to be registered in an issue already but it seems it got forgotten.

It should be perfectly possible to capture and display warnings during collection, so hopefully this is something that will be tackled in the internal warnings refactoring for 3.5.

@Lukas0907

This comment has been minimized.

Show comment
Hide comment
@Lukas0907

Lukas0907 Apr 29, 2018

I'm interested in seeing this fixed since it hides for example deprecation warnings from attrs. Would this be doable without intimate knowledge of the pytest codebase?

Lukas0907 commented Apr 29, 2018

I'm interested in seeing this fixed since it hides for example deprecation warnings from attrs. Would this be doable without intimate knowledge of the pytest codebase?

@nicoddemus

This comment has been minimized.

Show comment
Hide comment
@nicoddemus

nicoddemus Apr 29, 2018

Member

Hi @Lukas0907, unfortunately this needs some internal refactoring to be done correctly; thankfully this is something that we do intend to fix for 3.7. 👍

Member

nicoddemus commented Apr 29, 2018

Hi @Lukas0907, unfortunately this needs some internal refactoring to be done correctly; thankfully this is something that we do intend to fix for 3.7. 👍

@Lukas0907

This comment has been minimized.

Show comment
Hide comment
@Lukas0907

Lukas0907 Apr 30, 2018

Thanks a lot! Looking forward to 3.7 then. :)

Lukas0907 commented Apr 30, 2018

Thanks a lot! Looking forward to 3.7 then. :)

@nicoddemus

This comment has been minimized.

Show comment
Hide comment
@nicoddemus

nicoddemus Sep 6, 2018

Member

Closed by #3931

Member

nicoddemus commented Sep 6, 2018

Closed by #3931

@nicoddemus nicoddemus referenced this issue Sep 6, 2018

Closed

Pytest 3.8.0 broke some NumPy tests. #3945

0 of 4 tasks complete

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Sep 6, 2018

asottile added a commit that referenced this issue Sep 7, 2018

Merge pull request #3948 from nicoddemus/fix-changelog
Amend CHANGELOG with missing #3251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment