I'd like to use multiple fixtures in the same test suite to test SQLAlchemy model in various situations. What is the easiest way?
Asked
Active
Viewed 87 times
1 Answers
1
I use fixture methods that are invoked within a test:
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',))

zzzeek
- 72,307
- 23
- 193
- 185