Created
November 14, 2012 04:03
-
-
Save danilobellini/4070188 to your computer and use it in GitHub Desktop.
Strange behaviour with pytest + warnings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Nov 14 01:39:53 2012 | |
@author: Danilo J. S. Bellini | |
""" | |
from warnings import warn, catch_warnings | |
import pytest | |
class Warner(object): | |
def __init__(self): | |
self.data = [1, 2] | |
def pop(self): | |
return self.data.pop() | |
def bad(self): | |
""" Get warned, bro! """ | |
if self.data != []: | |
warn("Blah", Warning) | |
print "I was here!" | |
def test(): | |
bros = Warner() | |
bros.pop() | |
with catch_warnings(record=True) as warn_list: | |
bros.bad() | |
assert bros.data != [] | |
assert warn_list != [] | |
# Put the code below inside a | |
# if __name__ == "__main__": | |
# and the problem get solved...why? | |
pytest.main('"{0}"'.format(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================= test session starts ============================== | |
platform linux2 -- Python 2.7.3 -- pytest-2.2.4 | |
collecting ... collected 1 items | |
warnbug.py F | |
=================================== FAILURES =================================== | |
_____________________________________ test _____________________________________ | |
def test(): | |
bros = Warner() | |
bros.pop() | |
with catch_warnings(record=True) as warn_list: | |
bros.bad() | |
assert bros.data != [] | |
> assert warn_list != [] | |
E assert [] != [] | |
warnbug.py:34: AssertionError | |
------------------------------- Captured stdout -------------------------------- | |
I was here! | |
=========================== 1 failed in 0.02 seconds =========================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment