我在用派泰斯特写单元测试。我想对一个类进行单元测试,它的__init__方法中有一个连接到数据库的对象:
data_model.py
from my_pkg.data_base_wrapper import DataBaseWrapper
class DataModel:
def __init__(self):
self.db = DataBaseWrapper()
self.db.update_data()
def foo(self):
data = self.db.get_some_data()
# make some processing an
我正在尝试将py.test的与我的单元测试结合在一起,与unittest一起使用。我在项目的顶层(如描述的)将几个夹具放在conftest.py文件中,用@pytest.fixture装饰它们,并将它们的名称作为需要它们的测试函数的参数。
安装程序注册正确,如py.test --fixtures test_stuff.py所示,但是当我运行py.test时,我得到了NameError: global name 'my_fixture' is not defined。这似乎只有在我使用unittest.TestCase-but的子类时才会发生-- py.test文档似乎说它与un