diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2c364f..6c354e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: | @@ -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 diff --git a/IPython/testing/ipunittest.py b/IPython/testing/ipunittest.py index 5a940a5..4b10761 100644 --- a/IPython/testing/ipunittest.py +++ b/IPython/testing/ipunittest.py @@ -36,6 +36,7 @@ Authors # Stdlib import re +import sys import unittest from doctest import DocTestFinder, DocTestRunner, TestResults from IPython.terminal.interactiveshell import InteractiveShell @@ -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): diff --git a/IPython/testing/plugin/pytest_ipdoctest.py b/IPython/testing/plugin/pytest_ipdoctest.py index fd19ba4..fc8af13 100644 --- a/IPython/testing/plugin/pytest_ipdoctest.py +++ b/IPython/testing/plugin/pytest_ipdoctest.py @@ -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 @@ -15,25 +15,25 @@ import types 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 @@ -41,14 +41,15 @@ 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" @@ -271,6 +272,8 @@ def _get_runner( class IPDoctestItem(pytest.Item): + _user_ns_orig: Dict[str, Any] + def __init__( self, name: str, @@ -283,6 +286,7 @@ class IPDoctestItem(pytest.Item): self.dtest = dtest self.obj = None self.fixture_request: Optional[FixtureRequest] = None + self._user_ns_orig = {} @classmethod def from_parent( # type: ignore diff --git a/IPython/testing/tests/test_decorators.py b/IPython/testing/tests/test_decorators.py index 8bdc471..9eef690 100644 --- a/IPython/testing/tests/test_decorators.py +++ b/IPython/testing/tests/test_decorators.py @@ -9,6 +9,7 @@ import sys # Our own from IPython.testing import decorators as dec from IPython.testing.skipdoctest import skip_doctest +from IPython.utils.text import dedent #----------------------------------------------------------------------------- # Utilities @@ -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 diff --git a/setup.cfg b/setup.cfg index aa10155..31606a8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,6 @@ doc = docrepr matplotlib stack_data - pytest typing_extensions exceptiongroup %(test)s @@ -71,7 +70,7 @@ qtconsole = qtconsole terminal = test = - pytest + pytest<8 pytest-asyncio<0.22 testpath pickleshare