Skip to content

Commit d40e0df

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 aad9a3e commit d40e0df

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
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.3 (UNRELEASED)
6+
===================
7+
- 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>`_
8+
9+
510
0.23.2 (2023-12-04)
611
===================
712
- Fixes a bug that caused an internal pytest error when collecting .txt files `#703 <https://github.com/pytest-dev/pytest-asyncio/issues/703>`_

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
@@ -621,6 +622,10 @@ def scoped_event_loop(
621622
# kwargs is missing. These cases are handled correctly when they happen inside
622623
# Collector.collect(), but this hook runs before the actual collect call.
623624
return
625+
except SkipTest:
626+
# Users may also have a unittest suite that they run with pytest.
627+
# Therefore, we need to handle SkipTest to avoid breaking test collection.
628+
return
624629
# When collector is a package, collector.obj is the package's __init__.py.
625630
# pytest doesn't seem to collect fixtures in __init__.py.
626631
# 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)