conftest.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; either version 2 of the License, or
  4. # (at your option) any later version.
  5. # This program is distributed in the hope that it will be useful,
  6. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. # GNU General Public License for more details.
  9. # You should have received a copy of the GNU General Public License
  10. # along with this program; if not, write to the Free Software
  11. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12. ################################################################################
  13. import pytest
  14. from sqlalchemy import create_engine
  15. from sqlalchemy.orm import sessionmaker
  16. from daklib.database.all import Base
  17. Session = sessionmaker()
  18. @pytest.fixture(scope='session')
  19. def engine():
  20. engine = create_engine('sqlite://', echo=True)
  21. Base.metadata.create_all(engine)
  22. return engine
  23. @pytest.yield_fixture
  24. def session(engine):
  25. connection = engine.connect()
  26. trans = connection.begin()
  27. session = Session(bind=connection)
  28. yield session
  29. session.close()
  30. trans.rollback()
  31. connection.close()