Skip to content

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

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

Closed
nicoddemus opened this issue Oct 25, 2017 · 6 comments
Closed

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

nicoddemus opened this issue Oct 25, 2017 · 6 comments

Comments

@nicoddemus
Copy link
Member

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
nicoddemus added a commit to nicoddemus/py that referenced this issue Oct 25, 2017
@nicoddemus nicoddemus mentioned this issue Oct 26, 2017
@RonnyPfannschmidt
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member

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

@Whissi
Copy link

Whissi commented Feb 24, 2018

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
Copy link
Member

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

yan12125 pushed a commit to macports/macports-ports that referenced this issue Jul 6, 2018
Version 1.5.3 passed `tox-3.7 -e py37-pytest30`. pytest >= 3.1 is not
supported yet (pytest-dev/py#162), and pytest
2.9 does not work with Python 3.7 (pytest-dev/py#192)
@scarabeusiv
Copy link

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

@RonnyPfannschmidt RonnyPfannschmidt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants