Skip to content

raise unittest.SkipTest being treated as failures by pytest #6569

@blackboxsw

Description

@blackboxsw

Bug report

Migration to from unittest.TestCase -> pytest subclasses exposes a pytest behavior which now treats
unittest.skip and unittest.skipIf decorators as FAILURE instead of skips because unittest.skip*
only works properly on unittest.TestCase subclasses. When used on regular pytest-style classes (not
inheriting from unittest.TestCase), they raise unittest.case.SkipTest exceptions
that pytest doesn't handle, causing them to appear as failures.

Environment details

  • Cloud-init version: tip-of-main commit 3830ed6
  • Operating System Distribution: any with pytest version 9.0.0
  • Cloud provider, platform or installer type: N/A

Reproducer

tox -e py3
....
.tox/py3/bin/pytest tests/unittests/sources/test_azure_helper.py   tests/unittests/test_templating.py
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.13.7, pytest-9.0.0, pluggy-1.6.0
rootdir: /home/ubuntu/cloud-init
configfile: tox.ini
plugins: mock-3.15.1, cov-7.0.0, xdist-3.8.0
collected 129 items                                                                                                                                                                    

tests/unittests/sources/test_azure_helper.py ....................................FF..................................................................                            [ 80%]
tests/unittests/test_templating.py ...........F.............                                                                                                                     [100%]

======================================================================================= FAILURES =======================================================================================
____________________________________________________________________ TestOpenSSLManagerActions.test_pubkey_extract _____________________________________________________________________

args = (<tests.unittests.sources.test_azure_helper.TestOpenSSLManagerActions object at 0x7b8bf2bc87d0>,), kwargs = {}

    @functools.wraps(test_item)
    def skip_wrapper(*args, **kwargs):
>       raise SkipTest(reason)
E       unittest.case.SkipTest: todo move to cloud_test

/usr/lib/python3.13/unittest/case.py:156: SkipTest
__________________________________________________________________ TestOpenSSLManagerActions.test_parse_certificates ___________________________________________________________________

args = (<tests.unittests.sources.test_azure_helper.TestOpenSSLManagerActions object at 0x7b8bf2bc8910>,), kwargs = {}

    @functools.wraps(test_item)
    def skip_wrapper(*args, **kwargs):
>       raise SkipTest(reason)
E       unittest.case.SkipTest: todo move to cloud_test

/usr/lib/python3.13/unittest/case.py:156: SkipTest
________________________________________________________ TestTemplates.test_jinja_warns_on_missing_dep_and_uses_basic_renderer _________________________________________________________

args = (<tests.unittests.test_templating.TestTemplates object at 0x7b8bf2c2a890>,)
kwargs = {'caplog': <_pytest.logging.LogCaptureFixture object at 0x7b8bf25de120>, 'tmp_path': PosixPath('/tmp/pytest-of-ubuntu/pytest-14/test_jinja_warns_on_missing_de0')}

    @functools.wraps(test_item)
    def skip_wrapper(*args, **kwargs):
>       raise SkipTest(reason)
E       unittest.case.SkipTest: Jinja dependency present.

/usr/lib/python3.13/unittest/case.py:156: SkipTest
=============================================================================== short test summary info ================================================================================
FAILED tests/unittests/sources/test_azure_helper.py::TestOpenSSLManagerActions::test_pubkey_extract - unittest.case.SkipTest: todo move to cloud_test
FAILED tests/unittests/sources/test_azure_helper.py::TestOpenSSLManagerActions::test_parse_certificates - unittest.case.SkipTest: todo move to cloud_test
FAILED tests/unittests/test_templating.py::TestTemplates::test_jinja_warns_on_missing_dep_and_uses_basic_renderer - unittest.case.SkipTest: Jinja dependency present.
============================================================================ 3 failed, 126 passed in 0.70s =============================================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctly

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions