andy-maier / python-yagot

Yet Another Garbage Object Tracker for Python
Apache License 2.0
0 stars 0 forks source link

0.5.0: pytest is failing #56

Open kloczek opened 3 years ago

kloczek commented 3 years ago
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-yagot-0.5.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-yagot-0.5.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/python3 -Bm pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/python-yagot-0.5.0
plugins: yagot-0.5.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, asyncio-0.15.1, toolbox-0.5, xprocess-0.17.1, flaky-3.7.0, requests-mock-1.9.2, aiohttp-0.3.0, checkdocs-2.7.0, mock-3.6.1, rerunfailures-9.1.1, hypothesis-6.13.6
collected 104 items

. .                                                                                                                                                                  [  0%]
examples/test_1.py .                                                                                                                                                 [  1%]
examples/test_2.py F                                                                                                                                                 [  2%]
tests/plugintest/test_plugin.py .......x                                                                                                                             [ 10%]
tests/unittest/test_decorator.py .x..                                                                                                                                [ 14%]
tests/unittest/test_garbagetracker.py .........................................................................................                                      [100%]

================================================================================= FAILURES =================================================================================
____________________________________________________________________________ test_selfref_dict _____________________________________________________________________________

args = (), kwargs = {}, tracker = <yagot._garbagetracker.GarbageTracker object at 0x7fbe813cd1c0>, ret = None, location = 'test_2::test_selfref_dict'
@py_assert1 = [{'self': {'self': {'self': {'self': {'self': {...}}}}}}], @py_assert3 = False
@py_format4 = "\n~There were 1 collected or uncollectable object(s) caused by function test_2::test_selfref_dict:\n~\n~1: <class 'di...': {'self': {'self': {'self': {...}}}}}}] = <yagot._garbagetracker.GarbageTracker object at 0x7fbe813cd1c0>.garbage\n}"

    @functools.wraps(func)
    def wrapper_garbage_checked(*args, **kwargs):
        "Wrapper function for the garbage_checked decorator"
        tracker = GarbageTracker.get_tracker()
        tracker.enable(leaks_only=leaks_only)
        tracker.start()
        tracker.ignore_types(type_list=ignore_types)
        ret = func(*args, **kwargs)  # The decorated function
        tracker.stop()
        location = "{module}::{function}".format(
            module=func.__module__, function=func.__name__)
>       assert not tracker.garbage, tracker.assert_message(location)
E       AssertionError:
E         There were 1 collected or uncollectable object(s) caused by function test_2::test_selfref_dict:
E
E         1: <class 'dict'> object at 0x7fbe8149d980:
E         {'self': <Recursive reference to dict object at 0x7fbe8149d980>}
E
E       assert not [{'self': {'self': {'self': {'self': {'self': {...}}}}}}]
E        +  where [{'self': {'self': {'self': {'self': {'self': {...}}}}}}] = <yagot._garbagetracker.GarbageTracker object at 0x7fbe813cd1c0>.garbage

yagot/_decorators.py:67: AssertionError
========================================================================= short test summary info ==========================================================================
XFAIL tests/plugintest/test_plugin.py::test_uncollectable_incref
  Increased reference count is not detected
XFAIL tests/unittest/test_decorator.py::test_leaks_selfref_1
FAILED examples/test_2.py::test_selfref_dict - AssertionError:
================================================================ 1 failed, 101 passed, 2 xfailed in 14.98s =================================================================
sebastic commented 1 year ago

I get a different failure on Debian bookworm:

============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-7.2.1, pluggy-1.0.0+repack -- /usr/bin/python3.11
cachedir: .pytest_cache
rootdir: /build/yagot-0.5.0
collecting ... collected 93 items

tests/unittest/test_decorator.py::test_leaks_empty PASSED                [  1%]
tests/unittest/test_decorator.py::test_leaks_selfref_1 XFAIL             [  2%]
tests/unittest/test_decorator.py::test_leaks_selfref_2 PASSED            [  3%]
tests/unittest/test_decorator.py::test_leaks_selfref_3 PASSED            [  4%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_get_tracker PASSED [  5%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_init PASSED   [  6%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_enable[kwargs0] PASSED [  7%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_enable[kwargs1] PASSED [  8%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_enable[kwargs2] PASSED [  9%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_disable[True] PASSED [ 10%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_disable[False] PASSED [ 11%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_ignore[True] PASSED [ 12%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_ignore[False] PASSED [ 13%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-True-True-True] PASSED [ 15%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-True-True-False] PASSED [ 16%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-True-False-True] PASSED [ 17%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-True-False-False] PASSED [ 18%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-False-True-True] PASSED [ 19%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-False-True-False] PASSED [ 20%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-False-False-True] PASSED [ 21%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty test function-details0-False-False-False] PASSED [ 22%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-True-True-True] PASSED [ 23%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-True-True-False] PASSED [ 24%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-True-False-True] PASSED [ 25%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-True-False-False] PASSED [ 26%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-False-True-True] PASSED [ 27%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-False-True-False] PASSED [ 29%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-False-False-True] PASSED [ 30%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Standard dict with string-details1-False-False-False] PASSED [ 31%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-True-True-True] PASSED [ 32%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-True-True-False] PASSED [ 33%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-True-False-True] PASSED [ 34%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-True-False-False] PASSED [ 35%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-False-True-True] PASSED [ 36%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-False-True-False] PASSED [ 37%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-False-False-True] PASSED [ 38%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Empty OrderedDict creating garbage on Python 2.7-details2-False-False-False] PASSED [ 39%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-True-True-True] PASSED [ 40%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-True-True-False] PASSED [ 41%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-True-False-True] PASSED [ 43%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-True-False-False] PASSED [ 44%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-False-True-True] PASSED [ 45%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-False-True-False] PASSED [ 46%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-False-False-True] PASSED [ 47%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring no garbage-details3-False-False-False] PASSED [ 48%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-True-True-True] PASSED [ 49%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-True-True-False] PASSED [ 50%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-True-False-True] PASSED [ 51%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-True-False-False] PASSED [ 52%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-False-True-True] PASSED [ 53%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-False-True-False] PASSED [ 54%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-False-False-True] PASSED [ 55%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring incorrect 'list' type obj as garbage-details4-False-False-False] PASSED [ 56%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-True-True-True] PASSED [ 58%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-True-True-False] PASSED [ 59%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-True-False-True] PASSED [ 60%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-True-False-False] PASSED [ 61%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-False-True-True] PASSED [ 62%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-False-True-False] PASSED [ 63%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-False-False-True] PASSED [ 64%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type obj as garbage-details5-False-False-False] PASSED [ 65%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-True-True-True] PASSED [ 66%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-True-True-False] PASSED [ 67%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-True-False-True] PASSED [ 68%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-True-False-False] PASSED [ 69%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-False-True-True] PASSED [ 70%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-False-True-False] PASSED [ 72%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-False-False-True] PASSED [ 73%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[Self-referencing dict, ignoring correct 'dict' type name as garbage-details6-False-False-False] PASSED [ 74%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-True-True-True] PASSED [ 75%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-True-True-False] PASSED [ 76%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-True-False-True] PASSED [ 77%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-True-False-False] PASSED [ 78%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-True-True] PASSED [ 79%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-True-False] FAILED [ 80%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-False-True] PASSED [ 81%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-False-False] PASSED [ 82%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-True-True-True] PASSED [ 83%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-True-True-False] PASSED [ 84%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-True-False-True] PASSED [ 86%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-True-False-False] PASSED [ 87%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-False-True-True] PASSED [ 88%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-False-True-False] PASSED [ 89%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-False-False-True] PASSED [ 90%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type obj as garbage-details8-False-False-False] PASSED [ 91%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-True-True-True] PASSED [ 92%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-True-True-False] PASSED [ 93%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-True-False-True] PASSED [ 94%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-True-False-False] PASSED [ 95%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-False-True-True] PASSED [ 96%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-False-True-False] PASSED [ 97%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-False-False-True] PASSED [ 98%]
tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring correct 'SelfRef' type name as garbage-details9-False-False-False] PASSED [100%]

=================================== FAILURES ===================================
_ test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-True-False] _

desc = 'SelfRef class, ignoring no garbage'
details = {'exp_collected_types': [<class 'tests.unittest.test_decorator.SelfRef'>, <class 'dict'>], 'exp_uncollectable_types': [], 'func': <function func_class_selfref at 0x7fb08804e840>, 'ignore_types': None}
leaks_only = False, enable = True, ignore = False

    @pytest.mark.parametrize(
        "ignore", [True, False])
    @pytest.mark.parametrize(
        "enable", [True, False])
    @pytest.mark.parametrize(
        "leaks_only", [True, False])
    @pytest.mark.parametrize(
        "desc, details",
        TESTCASES_GARBAGETRACKER_TRACK)
    def test_GarbageTracker_track(desc, details, leaks_only, enable, ignore):
        # pylint: disable=unused-argument
        """
        Test function for tracking garbage using
        GarbageTracker.start()/stop()/garbage.
        """
        func = details['func']
        ignore_types = details['ignore_types']
        exp_collected_types = details['exp_collected_types']
        exp_uncollectable_types = details['exp_uncollectable_types']
        use_pdb = details.get('pdb', False)

        if use_pdb:
            import pdb  # pylint: disable=import-outside-toplevel
            pdb.set_trace()

        obj = GarbageTracker()

        if enable:
            obj.enable(leaks_only)

        obj.start()

        func()  # The code that might create leaks

        if ignore:
            obj.ignore()

        if ignore_types is not None:
            obj.ignore_types(ignore_types)

        obj.stop()

        if not enable:
            # If the tracker was not enabled, we should not see any garbage
            # reported.
            assert obj.garbage == []
        elif ignore:
            # If the tracker was enabled but then ignored, we should also see no
            # garbage reported.
            assert obj.garbage == []
        else:
            # If the tracker was enabled and not ignored, we will see garbage
            # reported (if there is expected garbage).
            if leaks_only:
                exp_garbage_types = exp_uncollectable_types
            else:
                exp_garbage_types = exp_collected_types
            if isinstance(exp_garbage_types, int):
                # We just check the number of objects
                assert len(obj.garbage) == exp_garbage_types
            else:
                assert isinstance(exp_garbage_types, list)
                # We check the types of the objects
                garbage_types = [type(o) for o in obj.garbage]
>               assert garbage_types == exp_garbage_types, \
                    "Garbage objects: {}".format(obj.garbage)
E               AssertionError: Garbage objects: [<tests.unittest.test_decorator.SelfRef object at 0x7fb088044450>]
E               assert [<class 'tests.unittest.test_decorator.SelfRef'>] == [<class 'tests.unittest.test_decorator.SelfRef'>, <class 'dict'>]
E                 Right contains one more item: <class 'dict'>
E                 Full diff:
E                 - [<class 'tests.unittest.test_decorator.SelfRef'>, <class 'dict'>]
E                 ?                                                 ----------------
E                 + [<class 'tests.unittest.test_decorator.SelfRef'>]

tests/unittest/test_garbagetracker.py:308: AssertionError
=========================== short test summary info ============================
FAILED tests/unittest/test_garbagetracker.py::test_GarbageTracker_track[SelfRef class, ignoring no garbage-details7-False-True-False]
=================== 1 failed, 91 passed, 1 xfailed in 0.44s ====================