Skip to content

Support unittest skiptest #715

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 2 commits into from
Dec 9, 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
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_pytest_skip.py → 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)