문제

I'm using nose to run some system tests, one of which is to test whether a (config) file exists. If this file exists, I'd like to run some additional tests on it. If not, I'd like to skip a bunch of tests.

What's the best approach to take to make nose include the additional tests if the main test passes?

도움이 되었습니까?

해결책

You could use skipTest from the setUp method in your specific TestCase, like:

import os
from unittest import TestCase

class MyTest(TestCase):
    def setUp(self):
        if not os.path.exists('configfile'):
            return self.skipTest('config file not found')

    def test01(self):
        # Do something with the file
        with open('configfile') as fd:
            self.assertEqual(fd.readlines().__len__(), 0)

test test01 would not run if config file does not exist.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top