Skip to content

pytest 9.0 errors instead of skipping when unittest.SkipTest is raised #13895

Closed

Description

@progval

This code:

import unittest

def test_skiptest():
    raise unittest.SkipTest()

had this behavior on pytest <9.0:

$ rm venv -r
$ python3 -m venv ./venv
$ ./venv/bin/pip install "pytest<9"
[...]
Successfully installed iniconfig-2.3.0 packaging-25.0 pluggy-1.6.0 pygments-2.19.2 pytest-8.4.2
$ ./venv/bin/pytest test.py
=== test session starts ===
platform linux -- Python 3.13.5, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/dev-irc
collected 1 item
test.py s        [100%]

=== 1 skipped in 0.03s ===

and this on pytest 9.0.0:

$ rm venv -r
$ python3 -m venv ./venv
$ ./venv/bin/pip install "pytest==9.0.0"
[...]
Successfully installed iniconfig-2.3.0 packaging-25.0 pluggy-1.6.0 pygments-2.19.2 pytest-9.0.0
$ ./venv/bin/pytest test.py
=== test session starts ===
platform linux -- Python 3.13.5, pytest-9.0.0, pluggy-1.6.0
rootdir: /home/dev-irc
collected 1 item
test.py F       [100%]

==== FAILURES ===
____ test_skiptest ____

    def test_skiptest():
>       raise unittest.SkipTest()
E       unittest.case.SkipTest

test.py:3: SkipTest
=== short test summary info ===
FAILED test.py::test_skiptest - unittest.case.SkipTest
=== 1 failed in 0.06s ===

Python version: 3.13.5

Activity

  1. bluetech commented on Nov 8, 2025

    @bluetech
    Member

    Thanks for the report.

    Bisected to a620d24 (@nicoddemus).

    However, you raising a unittest exception in a non-unittest test, is there a reason for that? Can you use pytest.skip() instead?

  2. bluetech commented on Nov 8, 2025

    @bluetech
    Member

    Just to clarify my comment, raising unittest.SkipTest still works inside a unittest TestCase.

  3. progval commented on Nov 8, 2025

    @progval
    Author

    It's inherited from before I used pytest.

    I actually use subclasses of unittest.SkipTest and I don't think I ever try to catch them in an except block so I should be able to convert them to functions wrapping pytest.skip(). But I imagine someone else might not.

  4. progval commented on Nov 8, 2025

    @progval
    Author

    Also, I have people not familiar with pytest on this codebase, and raise MySkipTestSubclass() probably makes the control flow clearer for them than calling my_pytestdotskip_wrapper()

  5. added
    type: regressionindicates a problem that was introduced in a release which was working previously
    plugin: unittestrelated to the unittest integration builtin plugin
    on Nov 8, 2025
  6. self-assigned this
    on Nov 8, 2025
  7. nicoddemus commented on Nov 8, 2025

    @nicoddemus
    Member

    Looking at the commit, this worked before due to nose support, which has since then been removed.

    I don't think we should continue to support this usage, TBH. Seems simple enough for users to adapt this code to use pytest.skip() instead.

    What do you folks think?

  8. mkmoisen commented on Nov 8, 2025

    @mkmoisen

    @bluetech

    raising unittest.SkipTest still works inside a unittest TestCase.

    That is not the case for me now in 9.0.0.

    Raising unittest.SkipTest inside of unittest.TestCase is resulting in pytests reporting an error instead of a skip.

    class TestFoo(unittest.TestCase):
    @classmethod
        def setUpClass(cls):
            if cls is Bar:
                raise unittest.SkipTest('Skip Bar tests as it is a base class')
    
  9. mkmoisen commented on Nov 8, 2025

    @mkmoisen

    @nicoddemus

    Please see my comment above. unittest.SkipTest is broken for me now when using it in a unittest.TestCase.

    Thank you.

  10. nicoddemus commented on Nov 8, 2025

    @nicoddemus
    Member

    Please see my comment above. unittest.SkipTest is broken for me now when using it in a unittest.TestCase.

    Oh if that's the case then definitely this is a problem. I will look into it, thanks!

  11. Berserker66 commented on Nov 8, 2025

    @Berserker66

    Yeah, chiming in from a project where pytest is entirely optional, everything is defined with pure unittest and people can run pytest over it if they want. The skips result in errors now when using pytest, but not when using the python included unittest runner.

  12. Zac-HD commented on Nov 9, 2025

    @Zac-HD
    Member

    Being able to raise unittest.SkipTest() without worrying about whether my users are running pytest or unittest is nice for other testing libraries like Hypothesis too, so I'd support restoring the old behavior 🙂

  13. added a commit that references this issue on Nov 9, 2025
  14. cjw296 commented on Nov 9, 2025

    @cjw296

    Yeah, I hit this here, which is using Sybil's skip parser (code).
    There's a weird thing in that error, whereby it looks like importing twisted ends up with unittest's SkipTest being replaced by twisted.trial.unittest.SkipTest just by way of importing twisted at some point, but I reproduced the problem folks are reporting above even with it uninstalled.

    I guess my feedback from a library maintainer is to please generously support SkipTest exceptions if at all possible 😓

  15. 15 remaining items

  16. added a commit that references this issue on Nov 10, 2025
    6a47389
  17. added a commit that references this issue on Nov 10, 2025
    17b82a4
  18. rayluo commented on Nov 11, 2025

    @rayluo

    Is there an ETA for this fix to be released as 9.0.1? Some of our test automation pipelines have been failing since the release of pytest 9.0.0 3 days ago.

  19. nicoddemus commented on Nov 11, 2025

    @nicoddemus
    Member

    Soon. 👍

    In fact we were about to release 9.0.1 today but ran into some problems: #13928. Thanks to @webknjaz the solution was found, I will trigger a new build shortly.

  20. added a commit that references this issue on Nov 14, 2025
  21. added a commit that references this issue on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

plugin: unittestrelated to the unittest integration builtin plugintype: regressionindicates a problem that was introduced in a release which was working previously

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions