Skip to content

Commit edb9ae0

Browse files
committed
[fix] Fixes a bug that caused an internal pytest error when using unittest.SkipTest in a module.
Signed-off-by: Michael Seifert <[email protected]>
1 parent e1415c1 commit edb9ae0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

docs/source/reference/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
0.23.3 (UNRELEASED)
66
===================
77
- 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>`_
8+
- 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>`_
89

910

1011
0.23.2 (2023-12-04)

pytest_asyncio/plugin.py

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Union,
2727
overload,
2828
)
29+
from unittest import SkipTest
2930

3031
import pytest
3132
from _pytest.outcomes import OutcomeException
@@ -622,6 +623,10 @@ def scoped_event_loop(
622623
# kwargs is missing. These cases are handled correctly when they happen inside
623624
# Collector.collect(), but this hook runs before the actual collect call.
624625
return
626+
except SkipTest:
627+
# Users may also have a unittest suite that they run with pytest.
628+
# Therefore, we need to handle SkipTest to avoid breaking test collection.
629+
return
625630
# When collector is a package, collector.obj is the package's __init__.py.
626631
# pytest doesn't seem to collect fixtures in __init__.py.
627632
# Using parsefactories to collect fixtures in __init__.py their baseid will end

tests/test_skips.py

+17
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,20 @@ async def test_is_skipped():
8888
)
8989
result = pytester.runpytest("--asyncio-mode=auto")
9090
result.assert_outcomes(errors=1)
91+
92+
93+
def test_unittest_skiptest_compatibility(pytester: Pytester):
94+
pytester.makepyfile(
95+
dedent(
96+
"""\
97+
from unittest import SkipTest
98+
99+
raise SkipTest("Skip all tests")
100+
101+
async def test_is_skipped():
102+
pass
103+
"""
104+
)
105+
)
106+
result = pytester.runpytest("--asyncio-mode=auto")
107+
result.assert_outcomes(skipped=1)

0 commit comments

Comments
 (0)