From 4fbd0a843206241c7b24ea2b694ffcf945069c28 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Sun, 19 Jan 2025 13:44:26 +0100 Subject: [PATCH 1/2] Make compatible with pytest-asyncio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pytest-asyncio` reads [1] `collector.obj` during test collection which raises an `ImportError` for `DocTestTextfilePlus`. We fix this by aligning that class with pytest’s `DoctestTextfile` [2] and setting `obj` to `None`. Fixes #256 [1]: https://github.com/pytest-dev/pytest-asyncio/blob/eb63d5ad0ca21041726ada3d5c00211d36418a9b/pytest_asyncio/plugin.py#L640 [2]: https://github.com/pytest-dev/pytest/blob/fc56ae365fcdea800f91683186136a8191e22399/src/_pytest/doctest.py#L421 --- .github/workflows/python-tests.yml | 3 +++ pytest_doctestplus/plugin.py | 1 + tests/test_doctestplus.py | 10 ++++++++++ tox.ini | 1 + 4 files changed, 15 insertions(+) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 91983dd..8bbb8b9 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -70,6 +70,9 @@ jobs: - os: ubuntu-latest python-version: '3.13' toxenv: py313-test-pytestdev-numpydev + - os: ubuntu-latest + python-version: '3.13' + toxenv: py313-test-pytest83-pytestasyncio steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 diff --git a/pytest_doctestplus/plugin.py b/pytest_doctestplus/plugin.py index 5290dd9..3f8e6da 100644 --- a/pytest_doctestplus/plugin.py +++ b/pytest_doctestplus/plugin.py @@ -342,6 +342,7 @@ def collect(self): test.name, self, runner, test) class DocTestTextfilePlus(pytest.Module): + obj = None def collect(self): if PYTEST_GE_7_0: diff --git a/tests/test_doctestplus.py b/tests/test_doctestplus.py index fb0ac37..6b54786 100644 --- a/tests/test_doctestplus.py +++ b/tests/test_doctestplus.py @@ -11,6 +11,13 @@ import doctest from pytest_doctestplus.output_checker import OutputChecker, FLOAT_CMP +try: + import pytest_asyncio # noqa: F401 + has_pytest_asyncio = True +except ImportError: + has_pytest_asyncio = False + + pytest_plugins = ['pytester'] @@ -1123,6 +1130,9 @@ class MyClass: assert ("something()\nUNEXPECTED EXCEPTION: NameError" in report.longreprtext) is cont_on_fail +@pytest.mark.xfail( + has_pytest_asyncio, + reason='pytest_asyncio monkey-patches .collect()') def test_main(testdir): pkg = testdir.mkdir('pkg') code = dedent( diff --git a/tox.ini b/tox.ini index eb158a0..d81ccfe 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,7 @@ deps = pytest83: pytest==8.3.* pytestdev: git+https://github.com/pytest-dev/pytest#egg=pytest numpydev: numpy>=0.0.dev0 + pytestasyncio: pytest-asyncio extras = test From 8c61c741855a890713326b4b10de8527b173996c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Tue, 21 Jan 2025 09:30:06 -0800 Subject: [PATCH 2/2] DOC: adding changelog [skip ci] --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8fe4a45..095e28f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,8 @@ 1.4.0 (unreleased) ================== +- Fixing compatibility with pytest-asyncio. [#278] + - Versions of Python <3.9 are no longer supported. [#274] 1.3.0 (2024-11-25)