Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在fixture中定义fixture的名称,然后按类名定义_Python_Sqlalchemy_Fixtures_Turbogears2 - Fatal编程技术网

Python 如何在fixture中定义fixture的名称,然后按类名定义

Python 如何在fixture中定义fixture的名称,然后按类名定义,python,sqlalchemy,fixtures,turbogears2,Python,Sqlalchemy,Fixtures,Turbogears2,我想在同一测试套件中使用多个fixture来测试各种情况下的SQLAlchemy模型。最简单的方法是什么?我使用在测试中调用的fixture方法: class TestMyStuff(TestCase): def setUp(self): self.Session = Session(bind=engine) def tearDown(self): self.Session.rollback() self.Session.clos

我想在同一测试套件中使用多个fixture来测试各种情况下的SQLAlchemy模型。最简单的方法是什么?

我使用在测试中调用的fixture方法:

class TestMyStuff(TestCase):
    def setUp(self):
        self.Session = Session(bind=engine)

    def tearDown(self):
        self.Session.rollback()
        self.Session.close()

    def _fixture_one(self):
        self.Session.add_all([
            User(name='ed')
        ])
        self.Session.flush()

    def _fixture_two(self):
        self.Session.add_all([
            Address(street='123 anywhere street')
        ])
        self.Session.flush()

    def test_some_user_thing(self):
        self._fixture_one()
        assert self.Session.query(User.name).first() == (('ed',))

    def test_some_address_thing(self):
        self._fixture_two()
        assert self.Session.query(Address.street).\
            first() == (('123 anywhere street',))