在python中运行unittest时,模块没有属性错误

时间:2014-02-06 10:50:52

标签: python dbus python-unittest

import avahi
import dbus

__author__ = 'michael'


class AvahiServicePublisher():

    def __init__(self):
        self.group = None
        bus = dbus.SystemBus()
        server = dbus.Interface(
            bus.get_object(
                avahi.DBUS_NAME,
                avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER)

        self.group = dbus.Interface(
            bus.get_object(avahi.DBUS_NAME,
                           server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP)

    def publish(self, name, port, stype="_http._tcp", domain="", host="", text=""):
        self.group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                              name, stype, domain, host,
                              dbus.UInt16(port), text)

        self.group.Commit()

    def unpublish(self):
        self.group.Reset()

这就是我运行unittest的方式

python -m unittest tests.AvahiTest

这是错误

Traceback (most recent call last):
  File "tests/AvahiTest.py", line 10, in setUp
    self.service_publisher = AvahiServicePublisher()
  File "avahi/AvahiServicePublisher.py", line 14, in __init__
    avahi.DBUS_NAME,
AttributeError: 'module' object has no attribute 'DBUS_NAME'

那么......如果没有这个错误我怎么能运行unittest?那个错误的原因是什么?

0 个答案:

没有答案