Skip to content

Commit

Permalink
[fix] Fixes a bug that caused an internal pytest error when collectin…
Browse files Browse the repository at this point in the history
…g .txt files.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Dec 4, 2023
1 parent a214c3e commit b614c77
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/source/reference/changelog.rst
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

0.23.2 (2023-12-04)
===================
- Fixes a bug that caused an internal pytest error when collecting .txt files `#703 <https://github.com/pytest-dev/pytest-asyncio/issues/703>`_


0.23.1 (2023-12-03)
===================
- Fixes a bug that caused an internal pytest error when using module-level skips `#701 <https://github.com/pytest-dev/pytest-asyncio/issues/701>`_
Expand Down
6 changes: 5 additions & 1 deletion pytest_asyncio/plugin.py
Expand Up @@ -609,7 +609,11 @@ def scoped_event_loop(
# collected Python class, where it will be picked up by pytest.Class.collect()
# or pytest.Module.collect(), respectively
try:
collector.obj.__pytest_asyncio_scoped_event_loop = scoped_event_loop
pyobject = collector.obj
# If the collected module is a DoctestTextfile, collector.obj is None
if pyobject is None:
return
pyobject.__pytest_asyncio_scoped_event_loop = scoped_event_loop
except (OutcomeException, Collector.CollectError):
# Accessing Module.obj triggers a module import executing module-level
# statements. A module-level pytest.skip statement raises the "Skipped"
Expand Down
20 changes: 20 additions & 0 deletions tests/test_doctest.py
Expand Up @@ -17,3 +17,23 @@ def any_function():
)
result = pytester.runpytest("--asyncio-mode=strict", "--doctest-modules")
result.assert_outcomes(passed=1)


def test_plugin_does_not_interfere_with_doctest_textfile_collection(pytester: Pytester):
pytester.makefile(".txt", "") # collected as DoctestTextfile
pytester.makepyfile(
__init__="",
test_python_file=dedent(
"""\
import pytest
pytest_plugins = "pytest_asyncio"
@pytest.mark.asyncio
async def test_anything():
pass
"""
),
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1)

0 comments on commit b614c77

Please sign in to comment.