Giter VIP home page Giter VIP logo

Comments (4)

RonnyPfannschmidt avatar RonnyPfannschmidt commented on May 23, 2024

this is a unfortunate side-effect of ensuring staying debugable

there was no effort yet to provide a api/hook to purge tracebakcs/stacktraces of expensive resources

in this case im considering the array a "resource" as its something that puts possibly large pressure onto the system and ought to be purged if disposable

from pytest.

ngchihuan avatar ngchihuan commented on May 23, 2024

Hi @RonnyPfannschmidt,
Thanks a lot for the follow-up.
Wondering what was the reason for not providing an api/hook to remove the traceback?
Or the pytest team does not have this in plans at all?
Is it complicated for a beginner to pytest repo like me to try to implement it?

from pytest.

ngchihuan avatar ngchihuan commented on May 23, 2024

For others who also encounter this issue in their tests,
I found a work-around

import weakref
import numpy as np
import pytest

N = 20_000_000

def get_data(n):
    d = np.random.rand(n,100)
    return d

def process_data(d):
    return np.diff(d)

def test1(data_provider):
    d = data_provider.get(N)
    process_data(d)
    assert False
    
def test2():
    d = get_data(N)
    process_data(d)
    
class DataFlyweight:
    def __init__(self):
        self._data =[]
        
    def get(self,n):
        if n not in self._data:
            self._data.append(get_data(n))
        return weakref.proxy(self._data[-1])

    def clear(self):
        self._data.clear()
    
@pytest.fixture
def data_provider():
    data_flyweight = DataFlyweight()
    yield data_flyweight
    data_flyweight.clear()

Memory does not explode and the second test passed as expected.

Screenshot 2024-04-11 at 16 26 17

from pytest.

RonnyPfannschmidt avatar RonnyPfannschmidt commented on May 23, 2024

Multiple reasons

Initially tracebacks where not attached to exceptions and extracting ex info typically lost a number of locals automatically

Also for most test suites memory intensive variables where no issue

So there was no incentive/pressure to work on a feature with limited win and excessive possible edge cases for a long time

from pytest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.