pytest-dev / py

Python development support library (note: maintenance only)
MIT License
67 stars 106 forks source link

apiwarn is not compatible with pytest >=3.1 on Windows #162

Closed nicoddemus closed 1 year ago

nicoddemus commented 6 years ago

apiwarn seems to conflict with the builtin warnings plugin introduced in pytest 3.1.

Error log:

_________________________ test_assert_within_finally __________________________
    def test_assert_within_finally():
        excinfo = py.test.raises(ZeroDivisionError, """
            try:
                1/0
            finally:
                i = 42
        """)
        s = excinfo.exconly()
>       assert re.search("division.+by zero", s) is not None
E       AssertionError: assert None is not None
E        +  where None = <function search at 0x01F46830>('division.+by zero', 'ZeroDivisionError: float division')
E        +    where <function search at 0x01F46830> = re.search
code\test_assertion.py:28: AssertionError
___________________________ test_apiwarn_functional ___________________________
recwarn = WarningsRecorder(record=True)
    def test_apiwarn_functional(recwarn):
        capture = py.io.StdCapture()
        py.log._apiwarn("x.y.z", "something", stacklevel=1)
        out, err = capture.reset()
        py.builtin.print_("out", out)
        py.builtin.print_("err", err)
>       assert err.find("x.y.z") != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of unicode object at 0x003EF038>('x.y.z')
E        +    where <built-in method find of unicode object at 0x003EF038> = ''.find
log\test_warning.py:16: AssertionError
---------------------------- Captured stdout call -----------------------------
out 
err 
_______________________________ test_stacklevel _______________________________
recwarn = WarningsRecorder(record=True)
    def test_stacklevel(recwarn):
        def f():
            py.log._apiwarn("x", "some", stacklevel=2)
        # 3
        # 4
        capture = py.io.StdCapture()
        f()
        out, err = capture.reset()
        lno = py.code.getrawcode(test_stacklevel).co_firstlineno + 6
        warning = str(err)
>       assert warning.find(":%s" % lno) != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of str object at 0x003EF050>((':%s' % 27))
E        +    where <built-in method find of str object at 0x003EF050> = ''.find
log\test_warning.py:31: AssertionError
____________________ test_stacklevel_initpkg_with_resolve _____________________
testdir = <Testdir local('c:\\users\\appveyor\\appdata\\local\\temp\\1\\pytest-0\\testdir\\test_stacklevel_initpkg_with_resolve0')>
recwarn = WarningsRecorder(record=True)
    def test_stacklevel_initpkg_with_resolve(testdir, recwarn):
        testdir.makepyfile(modabc="""
            import py
            def f():
                py.log._apiwarn("x", "some", stacklevel="apipkg123")
        """)
        testdir.makepyfile(apipkg123="""
            def __getattr__():
                import modabc
                modabc.f()
        """)
        p = testdir.makepyfile("""
            import apipkg123
            apipkg123.__getattr__()
        """)
        capture = py.io.StdCapture()
        p.pyimport()
        out, err = capture.reset()
        warning = str(err)
        loc = 'test_stacklevel_initpkg_with_resolve.py:2'
>       assert warning.find(loc) != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of str object at 0x003EF050>('test_stacklevel_initpkg_with_resolve.py:2')
E        +    where <built-in method find of str object at 0x003EF050> = ''.find
C:\projects\py\testing\log\test_warning.py:53: AssertionError
_____________________ test_stacklevel_initpkg_no_resolve ______________________
recwarn = WarningsRecorder(record=True)
    def test_stacklevel_initpkg_no_resolve(recwarn):
        def f():
            py.log._apiwarn("x", "some", stacklevel="apipkg")
        capture = py.io.StdCapture()
        f()
        out, err = capture.reset()
        lno = py.code.getrawcode(test_stacklevel_initpkg_no_resolve).co_firstlineno + 2
        warning = str(err)
>       assert warning.find(":%s" % lno) != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of str object at 0x003EF050>((':%s' % 57))
E        +    where <built-in method find of str object at 0x003EF050> = ''.find
log\test_warning.py:63: AssertionError
________________________________ test_function ________________________________
recwarn = WarningsRecorder(record=True)
    def test_function(recwarn):
        capture = py.io.StdCapture()
        py.log._apiwarn("x.y.z", "something", function=test_function)
        out, err = capture.reset()
        py.builtin.print_("out", out)
        py.builtin.print_("err", err)
>       assert err.find("x.y.z") != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of unicode object at 0x003EF038>('x.y.z')
E        +    where <built-in method find of unicode object at 0x003EF038> = ''.find
log\test_warning.py:72: AssertionError
---------------------------- Captured stdout call -----------------------------
out 
err
RonnyPfannschmidt commented 6 years ago

as far as i can tell apiwarn should be removed - it hid bad bugs in pytest for a while and my general eperience with it is shadowed due to that

nicoddemus commented 6 years ago

Should we add a warning about it somewhere then? Removing it is not really productive given that we are keeping some of the modules in py just with bare maintenance to avoid breaking things that depend on it still (the same reason we didn't remove py.code for example).

RonnyPfannschmidt commented 6 years ago

it needs a warning, from what i can tell it also incorrectly invokes the warnings module

Whissi commented 6 years ago

I think I am getting the same failure on Gentoo Linux with pytest version 3.2.2:

======================================================= FAILURES =======================================================
_______________________________________________ test_apiwarn_functional ________________________________________________

recwarn = WarningsRecorder(record=True)

    def test_apiwarn_functional(recwarn):
        capture = py.io.StdCapture()
        py.log._apiwarn("x.y.z", "something", stacklevel=1)
        out, err = capture.reset()
        py.builtin.print_("out", out)
        py.builtin.print_("err", err)
>       assert err.find("x.y.z") != -1
E       AssertionError: assert -1 != -1
E        +  where -1 = <built-in method find of str object at 0x7f8569bce848>('x.y.z')
E        +    where <built-in method find of str object at 0x7f8569bce848> = ''.find

testing/log/test_warning.py:26: AssertionError
------------------------------------------------- Captured stdout call ------------------------------------------------$
out
err
RonnyPfannschmidt commented 6 years ago

i beleive the tests need to be ported to the capsys fixture

scarabeusiv commented 5 years ago

The issue is not related to windows at all, the same issue can be observed on linux too. Full log py.txt