abalkin / pytest-leaks

A pytest plugin to trace resource leaks.
https://abalkin.github.io/pytest-leaks
Other
115 stars 4 forks source link

Not compatible with pytest 4 #10

Closed egabrum closed 5 years ago

egabrum commented 5 years ago

INTERNALERROR> File "c:\python37\lib\site-packages\pytest_leaks.py", line 90, in pytest_runtest_protocol INTERNALERROR> 'leakshunt') INTERNALERROR> TypeError: __init__() missing 3 required positional arguments: 'start', 'stop', and 'when'

Run on pytest 4.5.0, but it's probably been broken for a while.

seberg commented 5 years ago

I got it to run using this diff:

Git diff ```diff diff --git a/pytest_leaks.py b/pytest_leaks.py index 8736770..7d42326 100644 --- a/pytest_leaks.py +++ b/pytest_leaks.py @@ -86,8 +86,8 @@ class LeakChecker(object): hook.pytest_runtest_call(item=item) hook.pytest_runtest_teardown(item=item, nextitem=nextitem) - call = self.runner.CallInfo(lambda: self.hunt_leaks(run_test), - 'leakshunt') + call = self.runner.CallInfo.from_call( + lambda: self.hunt_leaks(run_test), 'leakshunt') if call.excinfo is None and call.result: self.leaks[item.nodeid] = call.result yield @@ -128,11 +128,14 @@ def hunt_leaks(func, nwarmup, ntracked): else: zdc = zipimport._zip_directory_cache.copy() abcs = {} - for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]: - if not isabstract(abc): - continue - for obj in abc.__subclasses__() + [abc]: - abcs[obj] = obj._abc_registry.copy() + #for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]: + # if not isabstract(abc): + # continue + # for obj in abc.__subclasses__() + [abc]: + # warnings.simplefilter("ignore") + # import IPython + # IPython.embed() + # abcs[obj] = obj._abc_registry.copy() repcount = nwarmup + ntracked rc_deltas = [0] * repcount alloc_deltas = [0] * repcount @@ -212,14 +215,14 @@ if _py3: sys._clear_type_cache() # Clear ABC registries, restoring previously saved ABC registries. - for a in collections.abc.__all__: - abc = getattr(collections.abc, a) - if not isabstract(abc): - continue - for obj in abc.__subclasses__() + [abc]: - obj._abc_registry = abcs.get(obj, WeakSet()).copy() - obj._abc_cache.clear() - obj._abc_negative_cache.clear() + # for a in collections.abc.__all__: + # abc = getattr(collections.abc, a) + # if not isabstract(abc): + # continue + # for obj in abc.__subclasses__() + [abc]: + # obj._abc_registry = abcs.get(obj, WeakSet()).copy() + # obj._abc_cache.clear() + # obj._abc_negative_cache.clear() # Flush standard output, so that buffered data is sent to the OS and # associated Python objects are reclaimed. ```

(the pytest change is only the from_call one. I also had to make sure to use the 5:5 syntax, I had also an issue that it would forward some parameters as strings from the pytest.ini and that breaks things (which may be OK, but the breaking was hidden away breaking everything).

seberg commented 5 years ago

I am using my diff very successfully to test numpy right now. Any chance we can maintain pytests-leaks a bit better? Once numpy is clean (at least minus f2py, but...) it can become very cool for more projects in that eco system maybe?