Files
libguestfs/python/t/test910Libvirt.py
Pino Toscano 9776615301 python: tests: refactor to use unittest's discovery
Instead of running all the tests manually, the unittest module has a
'discovery' mode to run tests by importing them from a directory: this
requires the tests to have different filenames, since they need to be
imported as modules now (hence an empty __init__.py is added), and the
current naming does not match the convention.

Using unittest as loader/runner brings another change: tests skipped as
whole cannot be done anymore with exit(77), since they are not run but
imported: thus introduce an helper module with decorators applied to the
test classes to skip them according to the current checks.  This also
gets us nicer recordings in the unittest log.

Due to the relative imports (needed for the helper code), it is no more
possible to execute tests anymore by invoking them manually; although
it is possible to run single tests, still using unittest's runner:

  $ cd python
  python$ ../run python -m unittest discover -v t test010Load.py

This does not change anything in what the tests do/check.
2016-02-22 16:57:15 +01:00

43 lines
1.4 KiB
Python

# libguestfs Python bindings
# Copyright (C) 2014 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# The Python bindings for add_libvirt_dom require the libvirt-python
# library to support a new method (.c_pointer()). Ensure this keeps
# working by testing it. See:
# https://bugzilla.redhat.com/show_bug.cgi?id=1075164
import unittest
import os
import sys
import guestfs
from .tests_helper import *
guestsdir = os.environ['guestsdir']
@skipUnlessLibirtHasCPointer ()
class Test910Libvirt (unittest.TestCase):
def test_libvirt (self):
import libvirt
conn = libvirt.open ("test:///%s/guests.xml" % guestsdir)
dom = conn.lookupByName ("blank-disk")
g = guestfs.GuestFS ()
r = g.add_libvirt_dom (dom, readonly=1)
self.assertEqual (r, 1)