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

pytest is leaking frames of tests that fail #2798

Closed
nicoddemus opened this Issue Sep 25, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@nicoddemus
Member

nicoddemus commented Sep 25, 2017

The test below reproduces the problem:

import weakref

class Obj:
    pass

ref = None

def test1():
    obj = Obj()
    global ref
    ref = weakref.ref(obj)
    assert 0

def test2():
    assert ref() is None

This fails with:

================================== FAILURES ===================================
____________________________________ test1 ____________________________________

    def test1():
        obj = Obj()
        global ref
        ref = weakref.ref(obj)
>       assert 0
E       assert 0

test_foo.py:15: AssertionError
____________________________________ test2 ____________________________________

    def test2():
>       assert ref() is None
E       assert <test_foo.Obj object at 0x0000017302911198> is None
E        +  where <test_foo.Obj object at 0x0000017302911198> = ref()

test_foo.py:19: AssertionError
========================== 2 failed in 0.04 seconds ===========================

The reference to test1's frame should not have leaked. If we comment the assert 0 line, then both tests pass.

xref: pytest-dev/pytest-qt#187

@nicoddemus nicoddemus self-assigned this Sep 25, 2017

nicoddemus added a commit to fabioz/pytest-qt that referenced this issue Sep 25, 2017

Add a test for exception leakage described in pytest-dev#187
Unfortunately at this moment this is still failing because
of pytest-dev/pytest#2798, we will need to fix this in pytest
first before being able to merge this.

@nicoddemus nicoddemus referenced this issue Nov 29, 2017

Closed

Memory usage in 3.3.0 #2968

4 of 4 tasks complete

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 11, 2018

Clear sys.last_* attributes before running an item
Otherwise we will keep the last failed exception around forever

Related to pytest-dev#2798

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 11, 2018

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 11, 2018

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 11, 2018

nicoddemus added a commit to fabioz/pytest-qt that referenced this issue Jul 12, 2018

Add a test for exception leakage described in pytest-dev#187
Unfortunately at this moment this is still failing because
of pytest-dev/pytest#2798, we will need to fix this in pytest
first before being able to merge this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment