mgedmin / objgraph

Visually explore Python object graphs
http://mg.pov.lt/objgraph/
MIT License
753 stars 72 forks source link

Tests fail under Python 3.11 #68

Closed mgedmin closed 1 year ago

mgedmin commented 1 year ago

Three tests fail under Python 3.11.0rc2+:

======================================================================
FAIL: /home/mg/src/objgraph/docs/generator-sample.txt
Doctest: generator-sample.txt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/opt/python311/lib/python3.11/doctest.py", line 2221, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for generator-sample.txt
  File "/home/mg/src/objgraph/docs/generator-sample.txt", line 0

----------------------------------------------------------------------
File "/home/mg/src/objgraph/docs/generator-sample.txt", line 43, in generator-sample.txt
Failed example:
    objgraph.show_chain(
        objgraph.find_backref_chain(objgraph.by_type('Canary')[0],
                                    objgraph.is_proper_module),
        filename='canary-chain.png')
Expected:
    Graph written to ....dot (11 nodes)
    Image generated as canary-chain.png
Got:
    Graph written to /tmp/test-objgraph-_jyc3mp_/objgraph-ah0l_c0o.dot (9 nodes)
    Image generated as canary-chain.png

======================================================================
FAIL: /home/mg/src/objgraph/docs/highlighting.txt
Doctest: highlighting.txt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/opt/python311/lib/python3.11/doctest.py", line 2221, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for highlighting.txt
  File "/home/mg/src/objgraph/docs/highlighting.txt", line 0

----------------------------------------------------------------------
File "/home/mg/src/objgraph/docs/highlighting.txt", line 16, in highlighting.txt
Failed example:
    objgraph.show_backrefs(a, max_depth=15,
        extra_ignore=[id(locals())],
        highlight=lambda x: isinstance(x, Node),
        filename='highlight.png')
Expected:
    Graph written to ....dot (12 nodes)
    Image generated as highlight.png
Got:
    Graph written to /tmp/test-objgraph-9ljbdx5m/objgraph-xu76dngb.dot (8 nodes)
    Image generated as highlight.png

======================================================================
FAIL: /home/mg/src/objgraph/docs/index.txt
Doctest: index.txt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/opt/python311/lib/python3.11/doctest.py", line 2221, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for index.txt
  File "/home/mg/src/objgraph/docs/index.txt", line 0

----------------------------------------------------------------------
File "/home/mg/src/objgraph/docs/index.txt", line 110, in index.txt
Failed example:
    objgraph.show_chain(
        objgraph.find_backref_chain(
            random.choice(objgraph.by_type('MyBigFatObject')),
            objgraph.is_proper_module),
        filename='chain.png')
Expected:
    Graph written to ...dot (13 nodes)
    Image generated as chain.png
Got:
    Graph written to /tmp/test-objgraph-c9315zw4/objgraph-7oqkrzee.dot (12 nodes)
    Image generated as chain.png

----------------------------------------------------------------------
Ran 58 tests in 2.392s

FAILED (failures=3, skipped=2)
stefanor commented 1 year ago

And 3.11.0 final.

mgedmin commented 1 year ago

I'm not sure what to do about this issue. As far as I know, there are no actual issues with using objgraph on Python 3.11. The tests are failing because 3.11 legitimately changed some internal implementation details.

In a unit test I could make the number of expected nodes contingent on the Python version. But I chose to use doctests a long time ago, and doctests add subtle pressure to make the test suite readable.

I could maybe ignore the node count for these particular tests.

In fact why don't I do that? I already have an IgnoreNodeCountChecker hooked to my DocFileSuite() so all I'd need is a # doctest: +NODES_VARY flag on these three failing tests.

I'd forgotten I had this.