Skip to content

Commit

Permalink
[fix] Fixes a bug that caused an internal pytest error when using uni…
Browse files Browse the repository at this point in the history
…ttest.SkipTest in a module.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Dec 9, 2023
1 parent e1415c1 commit edb9ae0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
0.23.3 (UNRELEASED)
===================
- Fixes a bug that caused event loops to be closed prematurely when using async generator fixtures with class scope or wider in a function-scoped test `#708 <https://github.com/pytest-dev/pytest-asyncio/issues/708>`_
- Fixes a bug that caused an internal pytest error when using unittest.SkipTest in a module `#711 <https://github.com/pytest-dev/pytest-asyncio/issues/711>`_


0.23.2 (2023-12-04)
Expand Down
5 changes: 5 additions & 0 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Union,
overload,
)
from unittest import SkipTest

import pytest
from _pytest.outcomes import OutcomeException
Expand Down Expand Up @@ -622,6 +623,10 @@ def scoped_event_loop(
# kwargs is missing. These cases are handled correctly when they happen inside
# Collector.collect(), but this hook runs before the actual collect call.
return
except SkipTest:
# Users may also have a unittest suite that they run with pytest.
# Therefore, we need to handle SkipTest to avoid breaking test collection.
return
# When collector is a package, collector.obj is the package's __init__.py.
# pytest doesn't seem to collect fixtures in __init__.py.
# Using parsefactories to collect fixtures in __init__.py their baseid will end
Expand Down
17 changes: 17 additions & 0 deletions tests/test_skips.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,20 @@ async def test_is_skipped():
)
result = pytester.runpytest("--asyncio-mode=auto")
result.assert_outcomes(errors=1)


def test_unittest_skiptest_compatibility(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
from unittest import SkipTest
raise SkipTest("Skip all tests")
async def test_is_skipped():
pass
"""
)
)
result = pytester.runpytest("--asyncio-mode=auto")
result.assert_outcomes(skipped=1)

0 comments on commit edb9ae0

Please sign in to comment.