Skip to content

Commit b614c77

Browse files
committed
[fix] Fixes a bug that caused an internal pytest error when collecting .txt files.
Signed-off-by: Michael Seifert <[email protected]>
1 parent a214c3e commit b614c77

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/source/reference/changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
0.23.2 (2023-12-04)
6+
===================
7+
- Fixes a bug that caused an internal pytest error when collecting .txt files `#703 <https://github.com/pytest-dev/pytest-asyncio/issues/703>`_
8+
9+
510
0.23.1 (2023-12-03)
611
===================
712
- Fixes a bug that caused an internal pytest error when using module-level skips `#701 <https://github.com/pytest-dev/pytest-asyncio/issues/701>`_

pytest_asyncio/plugin.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,11 @@ def scoped_event_loop(
609609
# collected Python class, where it will be picked up by pytest.Class.collect()
610610
# or pytest.Module.collect(), respectively
611611
try:
612-
collector.obj.__pytest_asyncio_scoped_event_loop = scoped_event_loop
612+
pyobject = collector.obj
613+
# If the collected module is a DoctestTextfile, collector.obj is None
614+
if pyobject is None:
615+
return
616+
pyobject.__pytest_asyncio_scoped_event_loop = scoped_event_loop
613617
except (OutcomeException, Collector.CollectError):
614618
# Accessing Module.obj triggers a module import executing module-level
615619
# statements. A module-level pytest.skip statement raises the "Skipped"

tests/test_doctest.py

+20
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@ def any_function():
1717
)
1818
result = pytester.runpytest("--asyncio-mode=strict", "--doctest-modules")
1919
result.assert_outcomes(passed=1)
20+
21+
22+
def test_plugin_does_not_interfere_with_doctest_textfile_collection(pytester: Pytester):
23+
pytester.makefile(".txt", "") # collected as DoctestTextfile
24+
pytester.makepyfile(
25+
__init__="",
26+
test_python_file=dedent(
27+
"""\
28+
import pytest
29+
30+
pytest_plugins = "pytest_asyncio"
31+
32+
@pytest.mark.asyncio
33+
async def test_anything():
34+
pass
35+
"""
36+
),
37+
)
38+
result = pytester.runpytest("--asyncio-mode=strict")
39+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)