Skip to content

Tests failing on Python 3.11 #231

Closed
Closed

Description

@jaraco

I should have been more cautious about merging this. It breaks on Python 3.11 (only, not 3.10 or 3.12) during test collection:

________________________________________________________ ERROR collecting path/__init__.py ________________________________________________________
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:942: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:1016: in _find
    self._find(tests, val, valname, module, source_lines,
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:1048: in _find
    self._find(tests, val, valname, module, source_lines,
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:1004: in _find
    test = self._get_test(obj, name, module, globs, source_lines)
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:1072: in _get_test
    lineno = self._find_lineno(obj, source_lines)
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py:1121: in _find_lineno
    obj = inspect.unwrap(obj).__code__
E   AttributeError: 'builtin_function_or_method' object has no attribute '__code__'

The issue was reported in python/cpython#117692.

Originally posted by @jaraco in #225 (comment)

Activity

  1. jaraco commented on Jul 27, 2024

    @jaraco
    OwnerAuthor

    Gemini seems to think I can disable doctest collection by providing a custom DoctestModule class. I'm not confident, but I'll give it a try.

  2. jaraco commented on Jul 27, 2024

    @jaraco
    OwnerAuthor

    Gemini seems to think I can disable doctest collection by providing a custom DoctestModule class. I'm not confident, but I'll give it a try.

    Gemini was wrong (big surprise). Adding an additional collector doesn't disable the build-in doctest collector.

    Here's the conftest I created that doesn't work:

    import pytest
    import sys
    
    
    def pytest_collect_file(parent, file_path):
        if file_path.suffix == ".py" and (3, 11, 9) <= sys.version_info < (3, 12):
            # Disable collection due to python/cpython#117692
            return DoctestModule.from_parent(parent, path=file_path)
    
    
    class DoctestModule(pytest.Module):
        def collect(self):
            return []  # Return an empty list to disable doctest collection
  3. added a commit that references this issue on Jul 27, 2024
    ade8831
  4. added a commit that references this issue on Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions