Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8078761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:53:59+00:00 2026-06-05T15:53:59+00:00

With the unittest module, I like the feature to skip tests , but it

  • 0

With the unittest module, I like the feature to skip tests, but it is only available in Python 2.7+.

For example, consider test.py:

import unittest
try:
    import proprietary_module
except ImportError:
    proprietary_module = None

class TestProprietary(unittest.TestCase):
    @unittest.skipIf(proprietary_module is None, "requries proprietary module")
    def test_something_proprietary(self):
        self.assertTrue(proprietary_module is not None)

if __name__ == '__main__':
    unittest.main()

If I try to run a test with an earlier version of Python, I get an error:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    class TestProprietary(unittest.TestCase):
  File "test.py", line 8, in TestProprietary
    @unittest.skipIf(proprietary_module is None, "requries proprietary module")
AttributeError: 'module' object has no attribute 'skipIf'

Is there a way to “trick” older versions of Python to ignore the unittest decorator, and to skip the test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:54:00+00:00Added an answer on June 5, 2026 at 3:54 pm

    unittest2 is a backport of the new features added to the unittest testing framework in Python 2.7. It is tested to run on Python 2.4 – 2.7.

    To use unittest2 instead of unittest simply replace
    import unittest
    with
    import unittest2

    Ref: http://pypi.python.org/pypi/unittest2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Python's unittest module for unit testing. I'd like to be able to
I'm writing a python module and I would like to unit test it. I
I'm using unittest and mock (Michael Foord's module) to test some python code. I
I`d like to know how I could unit-test the following module. def download_distribution(url, tempdir):
Is there a way, within IDLE, to run the PyUnit (unittest module) unit tests
I am using python unit test module. I am wondering is there anyway to
I have problem organizing my unittest based class test for family of tests. For
I would like to use the python logging module to log all of the
I am using Python's unittest with simple code like so: suite = unittest.TestSuite() suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(module1))
I have a python application like this / /crawl.py /crawl/__init__.py /crawl/john.py /tests/test_john.py What I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.