Skip to content

Unexpected behavior of skipping entire module when calling unittest.skip("a")("b") #10821

Open
@jogo

Description

@jogo

If aliasing unittest.skip with a value and inadvertently trying to pass an argument to the aliased copy, pytest will skip the entire module while unittest will throw an error.

import unittest

broken = unittest.skip("broken")


class MyTests(unittest.TestCase):
    @broken
    def test_good(self):
        assert False

    @broken("bar")
    def test_evil(self):
        assert False

pytest output

=============================================== test session starts ===============================================
platform darwin -- Python 3.11.2, pytest-7.2.2, pluggy-1.0.0
rootdir: ...
collected 0 items / 1 skipped

=============================================== 1 skipped in 0.01s ================================================

While running the same module via python -m unittest throws a unittest.case.SkipTest: broken error and fails loudly.

While the pattern of using the alias with a standard reason isn't a great pattern itself, nonetheless the behavior when it's used incorrectly is unprotected and easy to miss when you are trying to stable a test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin pluginstatus: help wanteddevelopers would like help from experts on this topictype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions