[issue17689] Fix test discovery for test_tarfile.py

Zachary Ware report at bugs.python.org
Mon Apr 15 19:03:13 CEST 2013


Zachary Ware added the comment:

That is indeed simpler than what I wrote, and it does work as expected.  But, is it preferable to do it this way, or with Ezio's suggested method (``skip_unless_gzip = unittest.skipUnless(gzip, "gzip not available")``, and for bz2 and lzma)?  I can see merits to both; mine only requires a docstring change if there's a new compression module sometime in the future, but Ezio's is simpler and shorter.

Here's another thought; would it be more useful to have a general version of this skip decorator in test.support, something along the lines of:

"""
def skipWithoutModule(name):
    """
    Skip if the named module is not available.
    """
    try:
        module = importlib.import_module(name)
    except ImportError:
        module = None

    return unittest.skipUnless(module, 
                               "{} module not available".format(name))
"""

And, actually, looking through test.support to see if there was anything like this already, I found requires_bz2 and requires_lzma that already exist; should I just add a requires_gzip to test.support and use those three in test_tarfile?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17689>
_______________________________________


More information about the Python-bugs-list mailing list