Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. @pytest.fixture(scope="session", autouse=True)
  2. def create_test_database():
  3. url = str(database.url)
  4. create_engine(url)
  5. if database_exists(url):
  6. drop_database(url)
  7. create_database(url) # Create the test database.
  8. p = os.path.join(os.getcwd(), "alembic.ini")
  9. m = os.path.join(os.getcwd(), "migrations")
  10. alembic_config = Config(p) # Run the migrations.
  11. alembic_config.set_main_option("script_location", m)
  12. alembic_config.attributes["configure_logger"] = False
  13. logger.debug("About to run alembic upgrade in tests")
  14. command.upgrade(alembic_config, "head")
  15. yield # Run the tests.
  16. drop_database(url) # Drop the test database.
  17. logger.debug("Drop db end of session fixture")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement