Skip to content

Fix collection error for .txt files #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/reference/changelog.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)