示例#1
0
    def test_run_list_with_loader(self):
        # list() is attempted with a loader first.
        self.useFixture(SampleTestFixture())
        tests = []

        class CaptureList(run.TestToolsTestRunner):
            def list(self, test, loader=None):
                tests.append(
                    set([
                        case.id()
                        for case in testtools.testsuite.iterate_tests(test)
                    ]))
                tests.append(loader)

        out = StringIO()
        try:
            program = run.TestProgram(
                argv=['prog', '-l', 'testtools.runexample.test_suite'],
                stdout=out,
                testRunner=CaptureList)
        except SystemExit:
            exc_info = sys.exc_info()
            raise AssertionError("-l tried to exit. %r" % exc_info[1])
        self.assertEqual([
            set([
                'testtools.runexample.TestFoo.test_bar',
                'testtools.runexample.TestFoo.test_quux'
            ]), program.testLoader
        ], tests)
示例#2
0
def main():
    logging.basicConfig(level=logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--skip-install',
        help=('skip the tests that install the example snaps into a snappy '
              'virtual machine'),
        action='store_true')
    parser.add_argument(
        '--ip',
        help=('IP of the testbed. If no IP is passed, a virtual machine will '
              'be created for the test.'))
    parser.add_argument(
        '--port', help=('SSH port of the testbed. Defaults to use port 22'))
    args = parser.parse_args()
    if args.skip_install:
        tests.config['skip-install'] = True
    if args.ip:
        tests.config['ip'] = args.ip
    if args.port:
        tests.config['port'] = args.port

    # Strip all the command line arguments, so unittest does not handle them
    # again.
    argv = [sys.argv[0]]
    run.TestProgram('examples_tests.tests', verbosity=2, argv=argv)
示例#3
0
def main():
    runner = SubunitTestRunner
    if sys.version_info[0] >= 3 and sys.version_info[1] >= 5:
        program.TestProgram(module=None,
                            argv=sys.argv,
                            testRunner=partial(runner, stdout=sys.stdout))
    else:
        from testtools import run as testtools_run
        testtools_run.TestProgram(module=None,
                                  argv=sys.argv,
                                  testRunner=runner,
                                  stdout=sys.stdout,
                                  exit=False)
示例#4
0
    def test_run_custom_list(self):
        self.useFixture(SampleTestFixture())
        tests = []

        class CaptureList(run.TestToolsTestRunner):
            def list(self, test):
                tests.append({
                    case.id()
                    for case in testtools.testsuite.iterate_tests(test)
                })

        out = io.StringIO()
        try:
            program = run.TestProgram(
                argv=['prog', '-l', 'testtools.runexample.test_suite'],
                stdout=out,
                testRunner=CaptureList)
        except SystemExit:
            exc_info = sys.exc_info()
            raise AssertionError("-l tried to exit. %r" % exc_info[1])
        self.assertEqual([{
            'testtools.runexample.TestFoo.test_bar',
            'testtools.runexample.TestFoo.test_quux'
        }], tests)