Skip to content

Commit

Permalink
Try to fix Pytest error on Python 3.13 (ipython#14287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Jan 10, 2024
2 parents 9699b3e + a282fc2 commit 001109a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
run: |
python -m pip install --only-binary ':all:' --upgrade pip setuptools wheel build
python -m pip install --only-binary ':all:' --no-binary curio --upgrade -e .[${{ matrix.deps }}]
python -m pip install --only-binary ':all:' --upgrade check-manifest pytest-cov pytest-json-report
python -m pip install --only-binary ':all:' --upgrade check-manifest pytest-cov pytest-json-report 'pytest<8'
- name: Install and update Python dependencies (dev?)
if: ${{ contains( matrix.python-version, 'dev' ) }}
run: |
Expand All @@ -84,7 +84,7 @@ jobs:
env:
COLUMNS: 120
run: |
pytest --color=yes -raXxs ${{ startsWith(matrix.python-version, 'pypy') && ' ' || '--cov --cov-report=xml' }} --json-report --json-report-file=./report-${{ matrix.python-version }}-${{runner.os}}.json
pytest --color=yes -raXxs ${{ startsWith(matrix.python-version, 'pypy') && ' ' || '--cov --cov-report=xml' }} --json-report --json-report-file=./report-${{ matrix.python-version }}-${{runner.os}}.json --maxfail=15
- uses: actions/upload-artifact@v3
with:
name: upload pytest timing reports as json
Expand Down
10 changes: 9 additions & 1 deletion IPython/testing/ipunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

# Stdlib
import re
import sys
import unittest
from doctest import DocTestFinder, DocTestRunner, TestResults
from IPython.terminal.interactiveshell import InteractiveShell
Expand All @@ -49,7 +50,14 @@ def count_failures(runner):
Code modeled after the summarize() method in doctest.
"""
return [TestResults(f, t) for f, t in runner._name2ft.values() if f > 0 ]
if sys.version_info < (3, 13):
return [TestResults(f, t) for f, t in runner._name2ft.values() if f > 0]
else:
return [
TestResults(failure, try_)
for failure, try_, skip in runner._stats.values()
if failure > 0
]


class IPython2PythonConverter(object):
Expand Down
42 changes: 23 additions & 19 deletions IPython/testing/plugin/pytest_ipdoctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# Copyright (c) 2004-2021 Holger Krekel and others
"""Discover and run ipdoctests in modules and test files."""
import builtins
import bdb
import builtins
import inspect
import os
import platform
Expand All @@ -15,40 +15,41 @@
import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Generator
from typing import Iterable
from typing import List
from typing import Optional
from typing import Pattern
from typing import Sequence
from typing import Tuple
from typing import Type
from typing import TYPE_CHECKING
from typing import Union
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Generator,
Iterable,
List,
Optional,
Pattern,
Sequence,
Tuple,
Type,
Union,
)

import pytest
from _pytest import outcomes
from _pytest._code.code import ExceptionInfo
from _pytest._code.code import ReprFileLocation
from _pytest._code.code import TerminalRepr
from _pytest._code.code import ExceptionInfo, ReprFileLocation, TerminalRepr
from _pytest._io import TerminalWriter
from _pytest.compat import safe_getattr
from _pytest.config import Config
from _pytest.config.argparsing import Parser
from _pytest.fixtures import FixtureRequest
from _pytest.nodes import Collector
from _pytest.outcomes import OutcomeException
from _pytest.pathlib import fnmatch_ex
from _pytest.pathlib import import_path
from _pytest.pathlib import fnmatch_ex, import_path
from _pytest.python_api import approx
from _pytest.warning_types import PytestWarning

if TYPE_CHECKING:
import doctest

from .ipdoctest import IPDoctestOutputChecker

DOCTEST_REPORT_CHOICE_NONE = "none"
DOCTEST_REPORT_CHOICE_CDIFF = "cdiff"
DOCTEST_REPORT_CHOICE_NDIFF = "ndiff"
Expand Down Expand Up @@ -271,6 +272,8 @@ def _get_runner(


class IPDoctestItem(pytest.Item):
_user_ns_orig: Dict[str, Any]

def __init__(
self,
name: str,
Expand All @@ -283,6 +286,7 @@ def __init__(
self.dtest = dtest
self.obj = None
self.fixture_request: Optional[FixtureRequest] = None
self._user_ns_orig = {}

@classmethod
def from_parent( # type: ignore
Expand Down
6 changes: 4 additions & 2 deletions IPython/testing/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Our own
from IPython.testing import decorators as dec
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils.text import dedent

#-----------------------------------------------------------------------------
# Utilities
Expand Down Expand Up @@ -89,10 +90,11 @@ def test_skip_dt_decorator():
>>> 1+1
3
"""

# Fetch the docstring from doctest_bad after decoration.
val = doctest_bad.__doc__
assert check == val, "doctest_bad docstrings don't match"

assert dedent(check) == dedent(val), "doctest_bad docstrings don't match"


# Doctest skipping should work for class methods too
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ doc =
docrepr
matplotlib
stack_data
pytest
typing_extensions
exceptiongroup
%(test)s
Expand All @@ -71,7 +70,7 @@ qtconsole =
qtconsole
terminal =
test =
pytest
pytest<8
pytest-asyncio<0.22
testpath
pickleshare
Expand Down

0 comments on commit 001109a

Please sign in to comment.