1

I have the following directory structure for my unit tests.

top/
    test1/
    test2/
    test3/
    ...

Each test1 directory has an __init__.py that contains a class such as TestSomething that does the actual testing.

To temporarily disable these tests, I have to go through each __init__.py file and add the @unittest.skip decorator to the TestSomething classes.

http://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures

As the number of tests has grown, this is becoming a tedious task because I have to go through each directory to disable the tests.

I am wondering if there's an easier way to disable all tests under a certain directory. For instance, is it possible to set something in top/__init__.py to turn off all tests in top?

4
  • How about move top directory outside the project directory temporarily, then restore when you're done ? Commented Jan 8, 2014 at 15:35
  • I would prefer not to move the top/ directory. Since all these directories/files are version controlled, I feel that that would lead to needless confusion. Commented Jan 8, 2014 at 15:38
  • How do you run the tests (which test runner do you use)? python -m unittest discover? Commented Jan 8, 2014 at 15:44
  • Well, I run nosetests from top/. I'm not sure if that is equivalent to python -m unittest discover. Commented Jan 8, 2014 at 16:02

1 Answer 1

2

It looks like unittest.skipIf(condition) from your linked page will do what you want.

Add unittest.skipIf(__skipThisDir__) to each test in a directory, as well as an import test_configuration at the top of the file.

Then add a "test_configuration.py" to each directory which contains

 __skipThisDir__ = False  #or True as needed
Sign up to request clarification or add additional context in comments.

1 Comment

That just seems to be a conditional way to skip individual tests. How/where can I use it to skip the entire directory of tests?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.