[New-bugs-announce] [issue34596] [unittest] raise error if @skip is used with an argument that looks like a test method

Naitree Zhu report at bugs.python.org
Thu Sep 6 09:05:21 EDT 2018


New submission from Naitree Zhu <naitreey at gmail.com>:

When using @skip decorator, `reason` argument is required. But one could easily overlook that and use it like so:

    class SomeTest(TestCase):

        @skip
        def test_method(self):
            # ...

The test actually passes when running with unittest, because it's equivalent to

    class SomeTest(TestCase):

        def test_method(self):
            # ...
        test_method = skip(test_method)

This gives the illusion that @skip decorator worked as expected.

I propose we should check the passed in `reason`, and raise error if it looks like a function/method, therefore prevent this erroneous usage.

In practice, this behavior has misled people using the decorator in the unintended way. For example: In this chapter of Test-Driven Development with Python (http://www.obeythetestinggoat.com/book/chapter_organising_test_files.html), the author used @skip decorator without `reason` argument.

----------
components: Library (Lib), Tests
messages: 324688
nosy: Naitree Zhu
priority: normal
severity: normal
status: open
title: [unittest] raise error if @skip is used with an argument that looks like a test method
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34596>
_______________________________________


More information about the New-bugs-announce mailing list